Open Source Your Knowledge, Become a Contributor

Nullability

A feature that makes Kotlin more valuable is its type system, and the management of nullability.

Kotlin help you to avoid the in-famous NPE (NullPointerException). You have to understand that
you may have NPE, even with Kotlin, but this will happen if you don't make enough effort.
Kotlin will help you think about how you code in a good way.

In Kotlin, each type is consider non-null, but each of those types have a derived type nullable. Nullable types
are followed by the ? character. For example, a non-null string will be written String and a nullable one will be
String?.

Accessing nullable values

Safe call operator ?.

Safe-calls allow you to call properties or functions from a nullable value. It combines a null check and an
invocation in a single expression. For example, s?.length is equivalent to if(s != null) s.length else null.
So if you are trying to invoke a property or a function upon a null value, it will use null as the value, instead
of throwing a NPE.