我想做以下几件事:
List<Integer> list = IntStream.range(0, 7).collect(Collectors.toList());
但在某种程度上,结果列表是Guava的ImmutableList
的实现。
我知道我能做到
List<Integer> list = IntStream.range(0, 7).collect(Collectors.toList());
List<Integer> immutableList = ImmutableList.copyOf(list);
但我想直接收集到它。我试过了
List<Integer> list = IntStream.range(0, 7)
.collect(Collectors.toCollection(ImmutableList::of));
但它抛出了一个异常:
com.google.common.collect.ImmutableCollection.add(ImmutableCollection.java:96)上的
java.lang.UnsupportedOperationException
https://stackoverflow.com/questions/29013250
复制相似问题