W3cubDocs

/Kotlin

compareAndSwap

Platform and version requirements: Native (1.3)
fun compareAndSwap(expected: T, new: T): T

Compares value with expected and replaces it with new value if values matches. Note that comparison is identity-based, not value-based. If new value is not null, it must be frozen or permanent object.

Parameters

expected - the expected value

new - the new value

Exceptions

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

Return the old value

© 2010–2020 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.native.concurrent/-atomic-reference/compare-and-swap.html