Nullability: Introduction
Nullability is a Kotlin feature that’s intended to help you eliminate NullPointerExceptions in your code. We all know that null pointer exceptions are bad, and the features I introduce in the following lessons are Kotlin’s way of eliminating them.
Two rules about using null values
Before you move into the following lessons, it’s worth mentioning that I like to think that there are two rules about using null values in Kotlin:
- Never use null values!
- When you’re forced to use null values — such as by using an old Java library — use Kotlin’s nullable types and the operators shown in the next few lessons.
With that point made, let’s jump into nullable types.