Nullable types
When you want to state that a reference type doesn’t point to a memory address, you can assign it a null value. If you have ever used Java, you probably experienced the NullPointerException fail, as it is one of the most common errors. This error is raised by the runtime when you dereference a null variable.
This decision, to have nulls in Java, is criticized a lot and is also sometimes called a Billion Dollar mistake. The introduction of the optional type in Java 8, tries to address this problem.
Kotlin tries to prevent these mistakes with supporting nullability in its type system. With nullable types, Kotlin tries to prevent null pointer errors during compilation and reduce the possibility of null pointer errors during runtime. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access