Lesson content
Read, practise, then check your understanding
A lambda implements the one abstract method of a target functional interface. Parameter types can usually be inferred.
Local behavior
int minimum = 5;
Predicate<String> longEnough = text -> text.length() >= minimum;
names.removeIf(String::isBlank);
names.sort(String::compareToIgnoreCase);
Captured locals must be final or effectively final. Capturing mutable objects still allows their mutation, which can complicate concurrency. Method references are concise when they remain obvious. Lambdas do not introduce an enclosing this like anonymous classes. Prefer short, side-effect-light lambdas; name complex logic for testing and reuse.
Knowledge check
Answer every question correctly to complete this chapter.
0 of 10 checks passed
Your progress is saved on this device.