That means the variable list
is final.
Which means you can not assign something else to it again.
Once you are done assign a value (reference) to it as follows:
private final List<Integer> list = new ArrayList<Integer>();
You can not do something as below again:
list = new ArrayList<Integer>(); //this is invalid because you are trying to assign something else the variable list
list.add(new Integer(123));
is this code valid?
It's perfectly valid. You are just adding an object to the ArrayList
that variable list
is referencing.
The usage of final
keyword is restricting the variable list
not the ArrayList
object that it's referencing.