Saturday, 14 July 2018

Can a functional interface have more than one method?


A Functional interface is the interface, which contains only one abstract method, but it can have multiple concrete methods.

Java 8 uses functional interfaces while implementing lambda expressions.

Some of the examples of functional interfaces
java.util.function.Predicate
java.util.function.Function
java.lang.Runnable

I Would recommend you go through my below tutorials to understand lambda expressions.

java.util.function.Function interface



As you see the above image, ‘java.util.function.Function’ interface is defined like above.
1.   @FunctionalInterface annotation is used to notify jvm that it is a functional interface
2.   R apply(T t) : It is an abstract method
3.   Remaining all methods are concrete.

You can get more information about functional interface in my below post.

You may like

No comments:

Post a Comment