Problem statement: What is the sense of final ArrayList?
It just mean that you cannot re-assign the reference to new collection object reference. Attempting to do it will lead compile time error.
e.g.
[1] -
final List<String> list = new ArrayList<String>();
list = new ArrayList<String>(); // Since `list' is final, this won't compile
linked = new LinkedList<String>(); // Since `linked' is final, this won't compile
^
compile time error here
Note: But I still can add to ArrayList new elements, remove elements and update it.
It just mean that you cannot re-assign the reference to new collection object reference. Attempting to do it will lead compile time error.
e.g.
[1] -
final List<String> list = new ArrayList<String>();
list = new ArrayList<String>(); // Since `list' is final, this won't compile
^
compile time error here
[2] -
final List<String> linked = new LinkedList<String>();linked = new LinkedList<String>(); // Since `linked' is final, this won't compile
^
compile time error here
Note: But I still can add to ArrayList new elements, remove elements and update it.
No comments:
Post a Comment