Files
Obsidian-Main/04. Programming/Kotlin/AtomicBoolean.md

25 lines
461 B
Markdown
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
[AtomicBoolean  |  Android Developers](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicBoolean)
## 初始化
```kotlin
val init = AtomicBoolean(false)
or
val inti = AtomicBoolean() // Default false
```
## read/write
`get()`取值,用`set()`設值
例:
```kotlin
if (init.get()) { ... } // 如果 init 是 true 的話
init.set(true) // 將 init 設為 true
```
## 其他function
### compareAndExchange
### compareAndSet