lazy的用法
class User {
val name:String by lazy { generateStr() }
private fun generateStr():String {
println("invoked!!")
return "Hello World"
}
}
fun main(args: Array<String>) {
val user = User()
println(user.name)
println(user.name)
}
複製程式碼