Does AtomicReference.compareAndSet(old,new) guarantee
old.fieldwasn't change?- Or it just guarantees
oldwasn't reassign to a new object?
if 2 is true, does it mean AtomicReference is useful only with immutable objects like String? (Because in case of mutability of old the old.field changes are lost with a successfully compareAndSet)
AtomicReferenceonly checks reference equality, and does not check for changes to fields.As a result, it is primarily only useful with immutable types.