0Pricing
Kotlin Academy · Lesson

Nullable and Non-Null Types

The type system basics.

Why Null Safety Matters

The infamous NullPointerException has crashed countless programs. Kotlin tackles this problem head-on by making nullability part of the type system.

In Kotlin, the compiler knows whether a value can be null or not, and it forces you to handle the possibility before you run into trouble.

Non-Null Types

By default, every type in Kotlin is non-null. A variable of type String can never hold null.

This guarantee is enforced at compile time, so you can use the value freely without checks.

fun main() {
    val name: String = "Alice"
    println(name.length)
}

All lessons in this course

  1. Nullable and Non-Null Types
  2. Safe Calls and Elvis
  3. The !! Operator
  4. Platform Types
← Back to Kotlin Academy