Functional interface
A functional interface or single abstract method interface is a special type of interface. It can still declare default methods, and even toString() without breaking the single-abstract-method constraint because the implementation can come from Object at runtime.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| @FunctionalInterface
interface MyFunctionalInterface {
void init();
default String addString(String str) {
return str + str;
}
String toString();
}
public class Day09 {
public static void main(String[] args) throws IOException, InterruptedException {
MyFunctionalInterface myFunctionalInterface =
() -> System.out.println("My functional Interface");
myFunctionalInterface.init();
}
}
|
The original LinkedIn graphic is preserved below.
