Saturday, June 16, 2018

What do you mean by final ArrayList?

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
^ 
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

How to run standalone mock server on local laptop

 Please download the standalone wiremock server from Direct download section at the bottom of the page.  Download and installation Feel fre...