ImmutableCollections
- collection 의 속성 중
Unmodifiable
을 지원하기 위한 팩토리 클래스
static abstract class AbstractImmutableCollection<E> extends AbstractCollection<E> { // all mutating methods throw UnsupportedOperationException @Override public boolean add(E e) { throwuoe(); } @Override public boolean addAll(Collection<? extends E> c) { throwuoe(); } @Override public void clear() { throwuoe(); } @Override public boolean remove(Object o) { throwuoe(); } @Override public boolean removeAll(Collection<?> c) { throwuoe(); } @Override public boolean removeIf(Predicate<? super E> filter) { throwuoe(); } @Override public boolean retainAll(Collection<?> c) { throwuoe(); } }
이런 식으로 모든 collection api중 원소를 mutate하는 api에 대해
UnsupportedOperationException
를 던짐AbstractImmutableCollection
를 List
, Set
, Map
의 형태로 구현하여 제공List.of
, Map.of
, Set.of
의 정적 팩토리 메서드에 대해 변형할 수 없는 콜렉션을 제공하는 역할을 함