The dreaded null pointer exception is a familiar sight to anyone who has been a Java developer for any length of time. It is caused by a failure to handle null references correctly. Avoiding these errors has been the subject of many different ideas in many different programming languages. In this chapter, we'll review Kotlin's approach to null safety. Speaking at QCon, a conference organized by the developer blogging site InfoQ, Tony Hoare, the creator of the null pointer, referred to nulls as his billion-dollar mistake.
There are several different approaches to solving this so-called billion-dollar mistake.
In C, it was common for code that referenced a null pointer to simply crash. Java improved on this by having a NullPointerException that would not crash the JVM but could be handled by a try/catch block; however, the onus...