How to avoid applied lazily Lists.transform in guava?

后端 未结 3 1668
死守一世寂寞
死守一世寂寞 2021-01-11 15:11
Map map = Maps.newHashMap();
map.put(\"test\",\"123\");
map.put(\"fuyou001\",\"456\");
map.put(\"id\",1         


        
3条回答
  •  长情又很酷
    2021-01-11 15:47

    Using an ImmutableList will force the values to be computed eagerly, and thus, no need for an extra copy afterwards. This is perhaps a more elegant solution:

    list = ImmutableList.copyOf(Lists.transform(list, 
      new Function, Object>() {
      @Override
      public Object apply(@Nullable Map input) {
        System.out.println("test:" + input);
        return input;
      }
    }));
    System.out.println(list);`
    

提交回复
热议问题