compareAndSet

Compares the current value to expected and if it matches, replaces with new value. If the result is successful, it returns true, otherwise false. The get and update operations are performed atomically. The new value must be an immutable object. Use toImmutable to make an immutable version of an object.

fun compareAndSet(expected: T, new: T): Boolean