Creating the final variable ensures that you cannot reassign this object reference after it is assigned. f you combine the last keyword using Collections.unmodifiableList, you ge the behavi
final List fixedList = Collections.unmodifiableList(someList);
This leads to the fact that the list pointed to by fixedList cannot be changed. it can still be changed using the someList link (so make sure that after this binding it goes out of scope.)
A simpler example is to use a rainbow class that adds rainbow colors to a hashset
public static class Rainbow { public static final Set VALID_COLORS; static { Set temp = new HashSet(); temp.add(Color.red); temp.add(Color.orange); temp.add(Color.yellow); temp.add(Color.green); temp.add(Color.blue); temp.add(Color.decode("#4B0082"));
source share