While studying the Collection
API, we find that some methods (add
, remove
,...) may throw a java.lang.UnsupportedOperationException>
Apart from the collections returned by the Collections.unmodifiable* methods, there are a couple more of interesting cases where UnsupportedOperationException
is actually thrown:
Collections.empty*
and Collections.singleton*
methods are also marked as "immutable", so - although it is not explicitly stated in the API docs - I suppose these throw the exception as well on attempts to modify them.