package com.richard.lambdaexpressions;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Predicate;
public class Roster3 {
public static void processPersons(List<Person> roster,
Predicate<Person> tester,
Consumer<Person> block){
for(Person p:roster){
if(tester.test(p)){
block.accept(p);
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
List<Person> roster=Person.createRoster();
processPersons(roster,
p->p.getGender()==Person.Sex.MALE &&
p.getAge()>=20 &&
p.getAge()<=45,
p->p.printPerson()
);
}
}
网友评论