Lambdas & Method References in Java

From the Java cheat sheet · Lambdas & Functional Interfaces · verified Jul 2026

Lambdas & Method References

Concise functions and the built-in functional interfaces.

java
// Quick Reference
Runnable r = () -> System.out.println("hi");
Function<Integer, Integer> sq = x -> x * x;
list.forEach(System.out::println);   // method reference
💡 A lambda can target any interface with exactly one abstract method (@FunctionalInterface).
⚡ Method references (Class::method) are shorthand for lambdas that just call one method.
📌 Predicate<T> -> boolean, Function<T,R> -> R, Consumer<T> -> void, Supplier<T> -> value.
🟢 Lambdas can capture effectively-final local variables from the enclosing scope.
lambdasfunctional
Back to the full Java cheat sheet