Why doesn't Kotlin allow to use lateinit with primitive types?

前端 未结 3 1207
-上瘾入骨i
-上瘾入骨i 2020-11-29 05:32

In the Kotlin language we, by default, have to initialize each variable when it is introduced. To avoid this, the lateinit keyword can be used. Referring to a <

3条回答
  •  我在风中等你
    2020-11-29 06:25

    I think that in case of primitives it's less resources taking to simply initialise it to let me say 0 and hold the simple value in memory rather than store extra information about the object nullability which is used by lateinit mechanism.

    Correct me if it's not the case.

提交回复
热议问题