Skip to content
Veltoryx Technologies
ProLesson 8.2Intermediate2 min readUpdated 30 October 2026

Functional interfaces

Meet Function, Predicate, Supplier, Consumer and their friends, combine them, and write your own with @FunctionalInterface.

A functional interface has exactly one abstract method, so a lambda can implement it. Java ships a set of ready-made ones in java.util.function, and four of them cover most needs.

01The big four

InterfaceMethodTakes → returnsThink of it as
Function<T, R>applyT → RTransform
Predicate<T>testT → booleanCheck a condition
Supplier<T>getnothing → TProduce a value
Consumer<T>acceptT → nothingDo something with a value
BigFour.java
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;

public class BigFour {
    public static void main(String[] args) {
        Function<String, Integer> length = s -> s.length();
        Predicate<String> isEmail = s -> s.contains("@");
        Supplier<String> newId = () -> "ID-" + 1001;
        Consumer<String> log = msg -> System.out.println("[log] " + msg);

        System.out.println(length.apply("Kafka"));
        System.out.println(isEmail.test("asha@veltoryx.dev"));
        System.out.println(newId.get());
        log.accept("order placed");
    }
}
Expected output
5
true
ID-1001
[log] order placed

Loading the rest of the lesson…