UnsupportedOperationException on Collection

后端 未结 4 948
醉酒成梦
醉酒成梦 2021-02-05 03:13

While studying the Collection API, we find that some methods (add, remove,...) may throw a java.lang.UnsupportedOperationException

4条回答
  •  不知归路
    2021-02-05 03:34

    Yes. For example when you call Collections.unmodifiableList(list), the returned list does not support add(..)

    These collections, however, are mostly private classes which are not exposed an an API, so you cannot instantiate them.

提交回复
热议问题