Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Please explain final AtomicReference

can someone explain me this:

final AtomicReference<Integer> atomicReference = new AtomicReference<>(1);
atomicReference.set(2);

In what sense is final used?

like image 606
GedankenNebel Avatar asked Dec 03 '22 23:12

GedankenNebel


1 Answers

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.)

like image 116
Jon Skeet Avatar answered Dec 12 '22 15:12

Jon Skeet