Problem
What will be the output?
val aVar by lazy {
println("I am computing this value")
"Hola"
}
fun main(args: Array<String>) {
println(aVar)
println(aVar)
}
For lazy
the first time you access the Lazy property, the initialisation (lazy()
function invocation) takes place. The second time, this value is remembered and returned:
I am computing this value
Hola
Hola