java中final修饰的变量不是不能被修改吗?为什么可以add添加?
怪我咯
怪我咯 2017-04-18 10:55:12
0
4
665

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(4)
黄舟

The searchableList variable itself cannot be modified, but the object pointed to by searchableList can be modified.

Peter_Zhu

The usage of this final is final variable, which means that the reference of the searchableList variable cannot be changed and has been locked on that ArrayList, but the ArrayList itself can be changed.

Ty80

Final modifies the heap memory space pointed to by the searchableList variable. For example, searchableList is your house. Being modified by final means that the house will not change anymore, but the content inside can be changed. You can also add things to the house. Go in or delete updates, etc.

小葫芦

The final modified searchableList is a reference, and this reference points to ArrayList<String>, so searchableList cannot be modified, and ArrayList is implemented with an array, and new elements can be added to this array.
When you try to modify the object ed pointed to by searchableList, an error is reported

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!