incrementAndFetch
Atomically increments the current value of this AtomicInt by one and returns the new value.
Since Kotlin
2.1Samples
import kotlin.concurrent.atomics.*
import kotlin.concurrent.thread
fun main() {
//sampleStart
val a = AtomicInt(7)
println(a.incrementAndFetch()) // 8
println(a.load()) // 8
//sampleEnd
}
Atomically increments the current value of this AtomicLong by one and returns the new value.
Since Kotlin
2.1Samples
import kotlin.concurrent.atomics.*
import kotlin.concurrent.thread
fun main() {
//sampleStart
val a = AtomicLong(7)
println(a.incrementAndFetch()) // 8
println(a.load()) // 8
//sampleEnd
}