+ 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
5 Answers
+ 3
Your welcome :)
Here is an article which explains why default methods are useful:
https://www.baeldung.com/java-static-default-methods
+ 4
thanks I got it
+ 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
+ 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
} }
+ 2
JavaGoal.com
thanks for this information