Behaviour as a parameter
public class Example {
public static void main(String[] args) {
public List<Order> find(Predicate<Order> criteria) {
return orders.stream().filter(criteria).toList();
}
find(order -> order.status() == Status.PENDING);
find(order -> order.status() == Status.PENDING && order.isOverdue());
}
}
Document whether a Consumer callback runs zero, one, or many times — streams and Optional differ.
The rest of this guide is part of Pro
Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.
Still to come · 3 sections
- Lambdas versus anonymous classes
- Partial application (manual currying)
- var in lambda parameters (Java 11+)
Test yourself
Answer these before moving on — recall is what makes it stick.