Παράδειγμα λάμδα

import java.util.function.Function;

class Lambda {
    public static void main(String args[]) {
        // Assign lambda to variable
        Function<Integer, Integer> square = (a) -> a * a;
        // Apply function to value
        System.out.println(square.apply(2));

        // Pass function to method and obtain function result
        Function<Integer, Integer> fourthPower = square.compose(square);
        System.out.println(fourthPower.apply(2));
    }
}