Lambdas and Functional Interfaces

A lambda is a compact implementation of a functional interface: an interface with one abstract method.

Predicate<String> nonEmpty = value -> !value.isBlank();
Function<String, Integer> length = String::length;
Consumer<String> log = System.out::println;

Common functional interfaces include Predicate<T>, Function<T,R>, Consumer<T>, and Supplier<T>. Primitive-specialized forms can reduce boxing in hot numeric code.

A lambda should generally be small. Complex behavior is often clearer as a named method.

Key Takeaways
  • A lambda targets a functional interface.
  • Method references can improve readability.
  • Prefer small, intention-revealing lambdas.