Functional Interfaces
About
A functional interface is an interface that has exactly one abstract method. Functional interfaces are ideal for use with lambda expressions and method references in Java 8 and beyond.
The
@FunctionalInterface
annotation is used to indicate a functional interface, but it is optional. When annotation is provided, the compiler ensures that a functional interface contains only one abstract method.Examples:
Runnable
,Callable
,Comparator
, and custom single-method interfaces.Lambda Expressions: Since Java 8, lambdas are used to instantiate functional interfaces, which greatly simplifies code and improves readability.
For more details, refer to the below page -
Last updated
Was this helpful?