toKotlinUuid
Converts this java.util.UUID value to the corresponding kotlin.uuid.Uuid value.
This function is convenient when one has a Java uuid and needs to interact with an API that accepts a Kotlin uuid. It can also be used to format or retrieve information that the Java uuid does not provide, e.g., javaUuid.toKotlinUuid().toByteArray()
.
Since Kotlin
2.0Samples
import kotlin.uuid.*
fun main() {
//sampleStart
val urlNamespace = Uuid.parse("6ba7b811-9dad-11d1-80b4-00c04fd430c8").toByteArray()
val url = "https://kotlinlang.org/api/core/kotlin-stdlib/".encodeToByteArray()
val javaUuid = java.util.UUID.nameUUIDFromBytes(urlNamespace + url)
println(javaUuid) // 49953a09-8fa4-3071-bcd4-d9d3bc84e5b2
println(javaUuid.toKotlinUuid().toHexString()) // 49953a098fa43071bcd4d9d3bc84e5b2
//sampleEnd
}