Functional Interface
FI are also called Single Abstract Method interfaces (SAM Interfaces). As name suggest, they permit exactly one abstract method inside them. Java 8 introduces an annotation @FunctionalInterface
- FI is valid even if the @FunctionalInterface annotation would be omitted. It is only for informing the compiler to enforce single abstract method inside interface.
- Also, since default methods are not abstract you’re free to add default methods to your functional interface as many as you like.
- Another important point to remember is that if an interface declares an abstract method overriding one of the public methods of java.lang.Object, that also does not count toward the interface’s abstract method count since any implementation of the interface will have an implementation from java.lang.Object or elsewhere. for example, below is perfectly valid functional interface.
-> Exactly one abstract method
-> Zero or more default methods
-> Zero or more static methods
-> Zero or more abstract methods taken from java.lang.Object
No Comments Yet!!