How to avoid applied lazily Lists.transform in guava?

后端 未结 3 1655
死守一世寂寞
死守一世寂寞 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 16:10

    To complement Louis' answer, you're using Lists.transform() as if it modified the original list, like Collections.sort(). It doesn't.

    You have to use the return value of Lists.transform() to see something happen, keeping in mind that it's a view which gets evaluated each and every time you call it. So if you need to use the result several times, as Louis said, do a copy in a new List (ArrayList, ImmutableList, etc.).

提交回复
热议问题