Java functional interfaces guide: Function, Predicate, Consumer, Supplier, method references, composition, and writing custom functional interfaces.
Functional Interfaces and Lambdas
A functional interface is an interface with exactly one abstract method. Lambdas and method references are shorthand for implementing these interfaces. Together, they are the foundation of Java's functional programming style - streams, Optional, and CompletableFuture all depend on them.
Quick start
Built-in functional interfaces
Java provides a rich set in java.util.function:
Core four
Two-argument variants
Specialised variants
Lambda syntax
Method references
Method references are a shorthand for lambdas that just call an existing method:
Composing functions
Functional interfaces provide default methods for composition:
Function composition
Predicate composition
Consumer chaining
Writing custom functional interfaces
Use @FunctionalInterface to enforce exactly one abstract method: