Guava의 Immutable Collection에 put/add 를 호출하면, UnsupportedOperationException 예외가 발생한다.
public class ImmutableTest {
@Test
public void test() {
ImmutableList<String> list = ImmutableList.of("1", "2");
list.add("put");
}
}
에러내용
java.lang.UnsupportedOperationException
at com.google.common.collect.ImmutableCollection.add(ImmutableCollection.java:96)
참고 : guava source
public abstract class ImmutableCollection<E> extends AbstractCollection<E>
implements Serializable {
/**
* Guaranteed to throw an exception and leave the collection unmodified.
*
* @throws UnsupportedOperationException always
* @deprecated Unsupported operation.
*/
@Deprecated
@Override
public final boolean add(E e) {
throw new UnsupportedOperationException();
}
'general java' 카테고리의 다른 글
[play1] It is indirectly referenced from required .class files (0) | 2015.12.23 |
---|---|
[guava] Files.toString(), Files.hash 예제 코드 (0) | 2015.12.21 |
[swift] enum 이슈 - Enum class does not have a value for 55 (0) | 2015.12.21 |
[jenkins] exit 값 활용하기 (0) | 2015.12.02 |
[spring boot] spring boot 1.3이 출시되었다. (0) | 2015.11.26 |