library
intermediateFunctional Interfaces
Know the key functional interfaces in java.util.function and how to compose them.
A functional interface has exactly one abstract method. The @FunctionalInterface annotation is optional but recommended — it causes a compile error if the interface has more than one abstract method.
Functional interfaces = standardized electrical outlets. Function is a two-prong (input/output), Consumer is one-prong (input only), Supplier has no prongs but provides power (output only).
Key Concepts
1
Core interfaces in java.util.function:
2
Function<T,R> — takes T, returns R. Method: apply(T). Compose with andThen() and compose().
Predicate<T> — takes T, returns boolean. Method: test(T). Combine with and(), or(), negate().
Consumer<T> — takes T, returns nothing. Method: accept(T). Chain with andThen().
Supplier<T> — takes nothing, returns T. Method: get().
UnaryOperator<T> — Function<T,T> (same input/output type).
BinaryOperator<T> — BiFunction<T,T,T>.
BiFunction<T,U,R>, BiConsumer<T,U>, BiPredicate<T,U> — two-argument versions.
3
Primitive specializations avoid autoboxing: IntFunction, LongPredicate, DoubleSupplier, ToIntFunction, IntUnaryOperator, etc.
4
Functional interfaces enable lambdas and method references. Any interface with one abstract method qualifies — including legacy interfaces like Runnable, Callable, Comparator.
5
Composing functions: Function<A,B>.andThen(Function<B,C>) creates A→C. Predicate.and()/or() combine predicates.