Thanks for your feedback!
Was this page helpful?
Represents a value with lazy initialization.
To create an instance of Lazy use the lazy function.
import kotlin.concurrent.thread fun main() { //sampleStart val answer: Int by lazy { println("Computing the answer to the Ultimate Question of Life, the Universe, and Everything") 42 } println("What is the answer?") // Will print 'Computing...' and then 42 println(answer) // 42 println("Come again?") // Will just print 42 println(answer) // 42 //sampleEnd }
xxxxxxxxxx
val answer: Int by lazy {
println("Computing the answer to the Ultimate Question of Life, the Universe, and Everything")
42
}
println("What is the answer?")
// Will print 'Computing...' and then 42
println(answer) // 42
println("Come again?")
// Will just print 42
println(answer) // 42
Thanks for your feedback!