The final
keyword indicates that the value of the variable will not change once it's initialized. That makes the most sense for primitives, where final int = 5;
means it can't be reassigned 6
.
For reference variables, it means that it can't be re-assigned to another reference, because the value is the reference to an object. But it doesn't stop you from modifying the contents of the array. It just stops you from doing another assignment to the reference variable. That's why the second piece of code doesn't work -- you assign it another object after it was already assigned for the first time.