value
Начиная с Kotlin: 1.0
abstract val value: T
Возвращает лениво инициализированное значение текущего экземпляра Lazy. После инициализации значение не должно изменяться до конца срока жизни этого экземпляра Lazy.
Примеры
import kotlin.concurrent.thread
fun main() {
//sampleStart
val answer: Lazy<Int> = lazy {
println("Computing the answer to the Ultimate Question of Life, the Universe, and Everything")
42
}
println("What is the answer?")
println(answer) // Lazy value not initialized yet.
println("Oh, now compute it please")
// Will print 'Computing...' and then 42
println(answer.value) // 42
println("Come again?")
// Will print 42
println(answer.value) // 42
//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/-lazy/value.html