Spec-Zone.ru › Kotlin 2

fetchAndIncrementAt

kotlin-stdlib/kotlin.concurrent.atomics/fetchAndIncrementAt

Версия Kotlin: 2.1

@ExperimentalAtomicApi
fun AtomicIntArray.fetchAndIncrementAt(index: Int): Int

Атомарно увеличивает на единицу элемент этого массива AtomicIntArray с указанным индексом и возвращает старое значение элемента.

Выбрасывает исключение

IndexOutOfBoundsException

если индекс выходит за пределы этого массива.

Примеры

import kotlin.concurrent.atomics.*
import kotlin.concurrent.atomics.AtomicArray
import kotlin.test.assertFailsWith

fun main() { 
   //sampleStart 
   val a = AtomicIntArray(intArrayOf(1, 2, 3))
println(a.fetchAndIncrementAt(1)) // 2
println(a.loadAt(1)) // 3
println(a.toString()) // [1, 3, 3] 
   //sampleEnd
}

@ExperimentalAtomicApi
fun AtomicLongArray.fetchAndIncrementAt(index: Int): Long

Атомарно увеличивает на единицу элемент этого массива AtomicLongArray с указанным индексом и возвращает старое значение элемента.

Выбрасывает исключение

IndexOutOfBoundsException

если индекс выходит за пределы этого массива.

Примеры

import kotlin.concurrent.atomics.*
import kotlin.concurrent.atomics.AtomicArray
import kotlin.test.assertFailsWith

fun main() { 
   //sampleStart 
   val a = AtomicLongArray(longArrayOf(1, 2, 3))
println(a.fetchAndIncrementAt(1)) // 2
println(a.loadAt(1)) // 3
println(a.toString()) // [1, 3, 3] 
   //sampleEnd
}

© 2010–2026 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.concurrent.atomics/fetch-and-increment-at.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API