Why can we change the unmodifiable list if we have the original one?

前端 未结 7 719
时光取名叫无心
时光取名叫无心 2020-12-10 15:56

By looking at the code of Collections class, i got to know that when we are using the method unmodifiableList(List list) or unmodifiableCollection(Coll

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-10 16:00

    From documentation:

    public static List unmodifiableList(List list)

    Returns an unmodifiable view of the specified list. This method allows modules to provide users with "read-only" access to internal lists. Query operations on the returned list "read through" to the specified list, and attempts to modify the returned list, whether direct or via its iterator, result in an UnsupportedOperationException.

提交回复
热议问题