Eslam
04/04/2024, 10:40 PMPablichjenkov
04/04/2024, 11:18 PMEslam
04/04/2024, 11:29 PMPablichjenkov
04/04/2024, 11:31 PMnon-null valid
, if it has value since it's creation. You use lateinit to break this rule, so the compiler does not enforce the above rule and trust that you will assign some value before using/accessing it.
The purpose of lateinit is usually comfort for developers laziness to not handle nullability properly at the cost of writing a few more lines.Pablichjenkov
04/04/2024, 11:33 PMPablichjenkov
04/04/2024, 11:34 PMlateinit
or force unwrap !!
Pablichjenkov
04/04/2024, 11:37 PMempty object initialization
or simply proper nullability handling with the safe operator ?
, or lazy
, are betterEslam
04/04/2024, 11:46 PMPablichjenkov
04/04/2024, 11:49 PMKlitos Kyriacou
04/05/2024, 8:01 AMInt
is implemented as a wrapped Integer
type. Is there anything technically preventing the compiler from treating a "lateinit Int" as a wrapped Integer which is null when not initialized?