// To remove this function DiyInterface interfaces, generic functions can be used as an alternative interface Predicate: https://blog.csdn.net/u011848397/article/details/89074794 public class The people2 { Private List <the Person> persons = new new the ArrayList <> (); public List <the Person> getMaleList (the Predicate <the Person> the predicateA) { // common function interface List <the Person> = RES new new the ArrayList <> (); persons.forEach (Person -> { IF (the predicateA. Test (Person)) { // abstract method called the Predicate Test res.add (Person); } }); return res; } } //还原: interface DiyInterface { boolean test(Person person); } public class People { private List<Person> persons= new ArrayList<Person>(); public List<Person> getMaleList(DiyInterface filter) {//自定义函数式接口 List<Person> res = new ArrayList<>(); persons.forEach((Person person) -> { if(filter.test (Person)) { //Method call PersonInterface res.add (Person); } }); return RES; } } public class the Person { }