// Predicate 判断是否拥有资格,Consumer 改变输入的值
案例
public static MyTest2 getV(MyTest2 a, Predicate<MyTest2> pre,Consumer<MyTest2> con){ if(pre.test(a)){ con.accept(a); } return a; } public static void main(String[] args) { MyTest2 a = new MyTest2(12,"ce"); System.out.println(getV(a,x-> x.getAge() > 12,x->x.setAge(13)).toString()); System.out.println(getV(a,x-> x.getAge() > 11,x->x.setAge(13)).toString()); }