Kotlin - Property initialization using “by lazy” vs. “lateinit”

后端 未结 8 1095
没有蜡笔的小新
没有蜡笔的小新 2020-11-29 14:50

In Kotlin if you don\'t want to initialize a class property inside the constructor or in the top of the class body, you have basically these two options (from the language r

8条回答
  •  旧巷少年郎
    2020-11-29 15:41

    If you are using Spring container and you want to initialize non-nullable bean field, lateinit is better suited.

        @Autowired
        lateinit var myBean: MyBean
    

提交回复
热议问题