can someone explain me this:
final AtomicReference<Integer> atomicReference = new AtomicReference<>(1);
atomicReference.set(2);
In what sense is final used?
In what sense is final used?
The variable itself is final. You can't change the variable's value to refer to a different AtomicReference
object.
Calling set
on the object and thus changing the data within the object isn't the same thing at all.
To put it in more real world terms, I can give you my home address and say, "You can't change where I live." That doesn't stop you from painting my front door green though (i.e. making a change to the house that the address refers to.)