fetchAndIncrement

Atomically increments the current value of this AtomicInt by one and returns the old value.

Since Kotlin

2.1

Samples

import kotlin.concurrent.atomics.*
import kotlin.concurrent.thread

fun main() { 
   //sampleStart 
   val a = AtomicInt(7)
println(a.fetchAndIncrement()) // 7
println(a.load()) // 8 
   //sampleEnd
}

Atomically increments the current value of this AtomicLong by one and returns the old value.

Since Kotlin

2.1

Samples

import kotlin.concurrent.atomics.*
import kotlin.concurrent.thread

fun main() { 
   //sampleStart 
   val a = AtomicLong(7)
println(a.fetchAndIncrement()) // 7
println(a.load()) // 8 
   //sampleEnd
}