Kotlin lazy property depending on another property initialized in init

前端 未结 1 1038
春和景丽
春和景丽 2021-01-19 16:23

I have the following class in Kotlin:

class Example {
    val name: String

    val lazyVar: String by lazy {
        name + \" something else\"
    }

    i         


        
1条回答
  •  不思量自难忘°
    2021-01-19 17:03

    Try

    class Example {
        val name: String
    
        init {
            name = "StackOverflow"
        }
    
        val lazyVar: String by lazy {
            name + " something else"
        }
    }
    

    0 讨论(0)
提交回复
热议问题