lateinit modifier is not allowed on primitive type properties in Kotlin

前端 未结 2 1122
故里飘歌
故里飘歌 2020-12-03 09:47

I am defining like a instance variable in kotlin and want to initialize it onCreate method of an activity.

var count:         


        
2条回答
  •  感动是毒
    2020-12-03 10:20

    There's no reason to leave it uninitialized. Just initialize it to 0 or -1.

    lateinit is for non-null object references that can't easily be initialized in the class body definition.

提交回复
热议问题