A functional interface is an interface that contains only one abstract method.
These interfaces are used primarily with lambda expressions and method references.
Example of a functional interface:
@FunctionalInterface
interface MyFunctional {
void doSomething();
}
Built-in Functional Interfaces
Java provides many built-in functional interfaces such as:
Predicate
Function
Consumer
Supplier
Predicate
Predicate<T>: Represents a Boolean-valued function of one argument.
Function
Function<T, R>: Represents a function that takes an argument of type T and returns a result of type R.
Consumer
Consumer<T>: Represents an operation that takes a single input argument and returns no result.
Supplier
Supplier<T>: Represents a function that supplies a result of type T without taking any arguments.
Key Points of Functional Interface
One abstract method
Can have multiple default or static methods
Can be used with lambda expressions
Comments