QuickDevGuide

Home › Java

Functional Interfaces & Lambdas — Java

Functional programming in Java was introduced in Java 8, allowing functions to be treated as first-class citizens. A Functional Interface is an interface that contains exactly one abstract method (SAM - Single Abstract Method). It can have any number of default or static methods. The @FunctionalInterface Annotation The @FunctionalInterface annotation is optional but recommended; it instructs the Java compiler to verify that the interface has only one abstract method. Core Built-in Functional Interfaces (java.util.function) Interface Method Signature Purpose Example Use Case Predicate<T> boolean test(T t) Evaluates a condition Filtering: p -> p.getPrice() > 100 Function<T, R> R apply(T t) Transforms input type T to R Mapping: User::getEmail Consumer<T> void accept(T t) Performs action…

Key Takeaways