I'm reading about lambda's on https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html
In Approach 1 they mention
"You would have to rewrite a lot of your API to accommodate this change. In addition, this approach is unnecessarily restrictive; what if you wanted to print members younger than a certain age, for example"
public static void printPersonsOlderThan(List<Person> roster, int age) {
for (Person p : roster) {
if (p.getAge() >= age) {
p.printPerson();
}
}
}
In Approach 5 they use lambda expression:
printPersons(
roster,
(Person p) -> p.getGender() == Person.Sex.MALE
&& p.getAge() >= 18
&& p.getAge() <= 25
);
However, even in this lambda expression, we have to modify the API when we want to modify the search criteria.
Why is using a lambda here better compared to using a custom method in the first approach?