+ 5

what is default method in interface and how to use it?

I see it in a challenge there is a defined method preceded by default keyword and there is something like interface c=()->print(); what is that? thanks for helping

3rd Sep 2019, 4:17 PM
ABADA S
ABADA S - avatar
5 Answers
+ 3
Your welcome :) Here is an article which explains why default methods are useful: https://www.baeldung.com/java-static-default-methods
3rd Sep 2019, 7:09 PM
Denise Roßberg
Denise Roßberg - avatar
+ 4
thanks I got it
3rd Sep 2019, 6:59 PM
ABADA S
ABADA S - avatar
+ 2
I made a code which show you the difference between default and abstract method: https://code.sololearn.com/cUMrwtSrc30m/?ref=app The other thing are called lambda expressions: https://code.sololearn.com/c5ZmQguR1rPp/?ref=app
3rd Sep 2019, 6:55 PM
Denise Roßberg
Denise Roßberg - avatar
+ 2
+ A functional interface is an interface that contains only one abstract method. Then lambda expressions can be used to instance of it. it can't have more abstract methods. but it can contains other default methods, because default is not abstract. interface Fnc { void message(); } public class Program { public static void main(String[] args) { Fnc my = ()-> System.out.println("Hello"); my.message(); // Hello } }
4th Sep 2019, 5:45 AM
zemiak
+ 2
JavaGoal.com thanks for this information
10th Jan 2020, 1:31 PM
ABADA S
ABADA S - avatar