5 · Intermediate · lesson 28 of 41
Lambdas & Functional Interfaces
Passing behavior as data.
Java
Runnable r = () -> System.out.println("hi");
Function<String,Integer> len = s -> s.length();
BiFunction<Integer,Integer,Integer> add = (a, b) -> a + b;
Predicate<String> nonEmpty = s -> !s.isEmpty();
// Method reference
list.forEach(System.out::println);Key takeaways
- ✓A lambda targets a functional interface — one abstract method.
- ✓Method references (Class::method) are compact lambda substitutes.