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

前端 未结 7 712
时光取名叫无心
时光取名叫无心 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:24
    1. you should go for creating new Object of a list, only when the original Object is going to be changed and you need a backup , when someone corrupts it , u can replace by new Object.

    2. To create a ummodifiable object, i will wrap the original object and prevent add ,remove by throwing exception. but u know ,i can change each object present in the list .like if u have a person object in an umodifiable list , i can still change the name of the person object in the list.

    0 讨论(0)
提交回复
热议问题