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()ここでは、(につれ、必要ですが)とにかく不変のリストを返しますか?
注Google GuavaのImmutableMultiimapを使用しています。
ありがとうございました。
' ImmutableMultimap番号を
asList()
を呼び出すことになりますImmutableList.copyOf(ImmutableCollection)
を呼び出すImmutableList
asList()
メソッドを持っています。それをコピーする必要はありません。しかし、リストが必要な場合は... – SaviorGoogle Guavaのドキュメント(http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/collect/ImmutableListMultimap.html)に記載されていますmmutableMultimap#getはImmutableListを返す ... –
user1974753
また、 'ImmutableList.copyOf'は実際には' ImmutableList'をコピーしません。 –