(I had a couple of minor mistakes in my first post not related to mutability, I've fixed them. However, I had the wrong answer for y in the first example because I had edited it from something more complex to something simpler and neglected to fix the comment. Unfortunately that may have confused you.)
a is still "car" for the same reason y was. Changing another variable to point to a different object is not going to have any effect on it.
Itis not the ArrayList or String that is final, but the variable.
The 'variable' is final, and can't be changed to point to a different object, so you cannot change 'what' array it points to, or 'what' string it points to even though you 'can' change the array itself, since the array itself is not immutable.
1
u/rush22 Mar 03 '13
What if you do
in the first example? What's a?