One of the most common pain points developers have with Java and a number of other languages has to do with accessing a member of a null reference. In most languages, this results in a null reference exception at runtime. Most Java developers know this as the NullPointerException.
Kotlin is designed to eliminate the possibility of running into null reference, exceptions as much as possible. As stated in Chapter 1, Setting Up for Android Development, there are only four possible reasons why you could run into a NullPointerException in Kotlin:
- An external Java code
- An explicit call to throw NullPointerException
- Usage of the !! operator (we'll learn more about this operator later)
- Data inconsistency regarding initialization
So how does Kotlin ensure this?