Nullable Types

After this lesson, you'll be able to recognize and use nullable types, and know how to work with nullables effectively by using Kotlin's special operators to safely access potentially null data.

Kotlin’s type system differentiates between nullable and non-nullable types. By default, types are non-nullable; you cannot get a null pointer exception from dereferencing it.

This is why Kotlin’s basic data types, such as Int, can map safely to Java’s primitive types, such as int, in the bytecode. Both can never be null.

Thus, all objects and types you’ve seen so far in this course were non-nullable. Trying to assign null to them would cause a compile-time error:

Get hands-on with 1000+ tech skills courses.