所有示例均在gihub(ssh_base)中====>https://github.com/chengyangyang

Predicate和Consumer接口的使用

 

  //  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());
    }

 

  

posted @ 2019-06-25 19:03  ☞书香门第☜  阅读(165)  评论(0编辑  收藏  举报
http://count.knowsky.com/count1/count.asp?id=434520&sx=1&ys=64"