Java FAQ: Top Questions
29. What are functional interfaces in Java?
A functional interface in Java is an interface with exactly one abstract method, used as a target for lambda expressions and method references. Introduced in Java 8, they enable functional programming.
- @FunctionalInterface: Optional annotation to enforce one abstract method.
-
Standard Examples:
Runnable,Predicate,Function,Consumer. - Custom Functional Interfaces: Define your own for specific lambda use cases.
- Use with Streams: Often used in Stream API operations.
