By now, you’ve seen a large part of Kotlin’s syntax in action. You’ve moved beyond creating basic code in Kotlin and are ready to enjoy some of Kotlin’s productivity features that can make your code more compact and readable. One of the essential features in Kotlin that helps improve the reliability of your code is its support for nullable types. Let’s look at the details.
Nullability is a feature of the Kotlin type system that helps you avoid NullPointerException (NPE) errors. As a user of a program, you’ve probably seen an error message similar to “An error has occurred: java.lang.NullPointerException,” with no additional details. On Android, you may have seen another version of this message, along the lines of “Unfortunately, application X has stopped,” which often also conceals a NullPointerException as a cause. Such errors occurring at run time are troublesome for both users and developers.