compareAndSwap

Native
1.3
fun compareAndSwap(expected: T, new: T): T
(source)

Compares value with expected and replaces it with new value if values matches. Note that comparison is identity-based, not value-based.

Legacy MM: if new value is not null, it must be frozen or permanent object.

Parameters

expected - the expected value

new - the new value

Exceptions

InvalidMutabilityException - with legacy MM if the value is not frozen or a permanent object

Return the old value