java 引用

static class Food{
        String id;
        String name;
       Food(String A,String B)
       {
           this.id=A;
           this.name=B;
       }
       public void setId(String id)
       {this.id=id;}
    }

    public static void main(String[] args) {
        Food a=new Food("a","b");
        Food b=new Food(null,"b");
        List<Food> list1=Lists.newArrayList(a,b);
        List<Food> list2=list1.stream().filter(i->i.id!=null).collect(Collectors.toList());
        list2.forEach(i->i.setId("x"));


    }

 

posted @ 2022-03-02 13:38  八英里  阅读(12)  评论(0编辑  收藏  举报