exchangeAt

expect fun exchangeAt(index: Int, newValue: T): T(source)

Atomically stores the new value into the element of this AtomicArray at the given index and returns the old value of the element.

Since Kotlin

2.1

Throws

if the index is out of bounds of this array.

Samples

import kotlin.concurrent.atomics.*

fun main() { 
   //sampleStart 
   val a = AtomicArray(arrayOf("aaa", "bbb", "ccc"))
println(a.exchangeAt(1, "kkk")) // bbb
println(a.loadAt(1)) // kkk
println(a.toString()) // [aaa, kkk, ccc] 
   //sampleEnd
}
actual fun exchangeAt(index: Int, newValue: T): T(source)

Atomically stores the new value into the element of this AtomicArray at the given index and returns the old value of the element.

Since Kotlin

2.1

Throws

if the index is out of bounds of this array.

actual fun exchangeAt(index: Int, newValue: T): T(source)

Atomically stores the new value into the element of this AtomicArray at the given index and returns the old value of the element.

Has the same memory effects as java.util.concurrent.atomic.AtomicReferenceArray.getAndSet.

Since Kotlin

2.1

Throws

if the index is out of bounds of this array.

actual fun exchangeAt(index: Int, newValue: T): T(source)

Atomically stores the new value into the element of this AtomicArray at the given index and returns the old value of the element.

Since Kotlin

2.1

Throws

if the index is out of bounds of this array.

actual fun exchangeAt(index: Int, newValue: T): T(source)

Atomically stores the new value into the element of this AtomicArray at the given index and returns the old value of the element.

Since Kotlin

2.1

Throws

if the index is out of bounds of this array.

actual fun exchangeAt(index: Int, newValue: T): T(source)

Atomically stores the new value into the element of this AtomicArray at the given index and returns the old value of the element.

Since Kotlin

2.1

Throws

if the index is out of bounds of this array.