You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p><a href="https://github.com/JetBrains/kotlin/releases/tag/v2.1.20-Beta2" target="_blank">Release on GitHub</a></p>
49
49
</td>
50
50
<td>
51
51
<p>A tooling release with K2 kapt enabled by default.</p>
52
-
<p>For more details, please refer to the <a href="https://github.com/JetBrains/kotlin/releases/tag/v2.1.20-Beta1">changelog</a> or <a href="whatsnew-eap.md">What's new in Kotlin 2.1.20-Beta1</a>.</p>
52
+
<p>For more details, please refer to the <a href="https://github.com/JetBrains/kotlin/releases/tag/v2.1.20-Beta2">changelog</a> or <a href="whatsnew-eap.md">What's new in Kotlin 2.1.20-Beta2</a>.</p>
To enable seamless interoperability between Kotlin's atomic types and Java's [`java.util.concurrent.atomic`](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/package-summary.html)
159
+
atomic types, the API provides the `.asJavaAtomic()` and `.asKotlinAtomic()` extension functions. On the JVM, Kotlin
160
+
atomics and Java atomics are the same types in runtime, so you can transform Java atomics to Kotlin atomics and the other
161
+
way around without any overhead.
162
+
163
+
Let's look at an example that shows how Kotlin and Java atomic types can work together:
164
+
165
+
```kotlin
166
+
// Imports the necessary libraries
167
+
importkotlin.concurrent.atomics.*
168
+
importjava.util.concurrent.atomic.*
169
+
170
+
//sampleStart
171
+
@OptIn(ExperimentalAtomicApi::class)
172
+
funmain() {
173
+
// Converts Kotlin AtomicInt to Java's AtomicInteger
174
+
val kotlinAtomic =AtomicInt(42)
175
+
val javaAtomic:AtomicInteger= kotlinAtomic.asJavaAtomic()
176
+
println("Java atomic value: ${javaAtomic.get()}")
177
+
// Java atomic value: 42
178
+
179
+
// Converts Java's AtomicInteger back to Kotlin's AtomicInt
180
+
val kotlinAgain:AtomicInt= javaAtomic.asKotlinAtomic()
### Changes in UUID parsing and formatting functions
189
+
<primary-labelref="experimental-opt-in"/>
190
+
191
+
The JetBrains team continues to improve the support for UUIDs [introduced to the standard library in 2.0.20](whatsnew2020.md#support-for-uuids-in-the-common-kotlin-standard-library).
192
+
193
+
Previously, the `parse()` function only accepted UUIDs in the hex-and-dash format. With Kotlin %kotlinEapVersion%,
194
+
you can use `parse()` for _both_ the hex-and-dash and the plain hexadecimal format (without dashes).
195
+
196
+
We also introduce functions specific to the operations with the hex-and-dash format in this release:
197
+
198
+
*`parseHexDash()` that parses UUIDs from the hex-and-dash format.
199
+
*`toHexDashString()` that converts a UUID into a string in the hex-and-dash format (mirroring the `toString()` functionality).
200
+
201
+
These functions work similarly to [`parseHex()`](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.uuid/-uuid/-companion/parse-hex.html)
202
+
and [`toHexString()`](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.uuid/-uuid/to-hex-string.html) that were
203
+
introduced earlier for the hexadecimal format. Explicit naming for the parsing and formatting functionality should improve
204
+
code clarity and your overall experience with UUID handling.
205
+
206
+
Remember that the UUID support in the standard library is still [Experimental](components-stability.md#stability-levels-explained).
207
+
To opt in, use the `@ExperimentalUuidApi` annotation or the compiler option `-opt-in=kotlin.uuid.ExperimentalUuidApi`:
208
+
209
+
```kotlin
210
+
importkotlin.uuid.ExperimentalUuidApi
211
+
importkotlin.uuid.Uuid
212
+
213
+
//sampleStart
214
+
@OptIn(ExperimentalUuidApi::class)
215
+
funmain() {
216
+
// Use parse() to accept a UUID in a plain hexadecimal format
217
+
val uuid =Uuid.parse("550e8400e29b41d4a716446655440000")
0 commit comments