0
我有以下代码:将不可变列表传递给ImmutableList.copyOf()?
private static final ImmutableMultimap<String, String> namesToAddress;
public static List<String> getAddresses(String name){
return ImmutableList.copyOf(namesToAddress.get(name));
}
我的问题是wheter防守copyOf()这里是必要的,因为get()返回反正不可改变的名单?
注意我用的ImmutableMultiimap从谷歌番石榴。
感谢。
'ImmutableMultimap#GET'返回'ImmutableCollection'。没有必要复制它。如果您需要。然而'List' ... – Savior
在谷歌番石榴文档(http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/collect/ImmutableListMultimap.html)它规定mmutableMultimap#GET返回ImmutableList ... –
user1974753
另外'ImmutableList.copyOf'实际上不会反正复制'ImmutableList'。 –