Functional Interface In Java
An interface which has only one abstract method defined is coined as functional interface. The interface can consist of any number of default methods and static methods. This feature was introduced in version 8 of Java.
To remember
- All methods in interface are abstract by default.
- Annotation
@java.lang.FunctionalInterface
is used.
- Only one abstract method is allowed.
- Abstract method should return something.
- Multiple default methods are permitted.
- More than one static methods are permitted.
- Lambda function have to be used when initialising the interface.
- When the class the implements the interface, then the abstract method has to be overridden ie @Override
Sample code