As we know in Java 8, the concept of functional interfaces are introduced. A Functional Interface has one abstract
method and several default or static methods are possible.
But why should a Functional interface have only one abstract method? If Interface has more then one abstract method, why is this not a Functional Interface?
A functional interface is an interface that contains only one abstract method. They can have only one functionality to exhibit.
The @FunctionalInterface Annotation When this annotation is specified on an interface, a compilation error will occur if the interface has more than one abstract method.
A functional interface must have exactly one abstract method. A functional interface has any number of default methods because they are not abstract and implementation already provided by the same.
Java 8 Functional Interfaces. A functional interface is an interface that has only one abstract method. It can contain any number of default and static methods but the abstract method it contains is exactly one.
The functional interface also known as Single Abstract Method Interface was introduced to facilitate Lambda functions. Since a lambda function can only provide the implementation for 1 method it is mandatory for the functional interface to have ONLY one abstract method. For more details refer here.
Edit -> Also worth noting here is that, a functional interface can have a default implementation in the interface. You will find a lot more details on the implementation on the link above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With