Comment by mike_hearn
10 hours ago
A lot of the language rules are required to make its approach to nullability work. Hence odd keywords like "lateinit var".
10 hours ago
A lot of the language rules are required to make its approach to nullability work. Hence odd keywords like "lateinit var".
`lateinit var` was not added to Kotlin to handle nullability, but to address specific Android design where system components like Activity cannot realisticly initialize fields in their constructors. Outside of Android it shouldn't be too commonly used.
"lateinit var" predates Android's adoption of Kotlin by years and was added because fields initialized after construction by frameworks are common in many contexts, but having nullability in the language makes that annoying.