0Pricing
Android Academy · Lesson

Null Safety

Understand Kotlin's null safety system: nullable types, the safe call operator, the Elvis operator, and how to eliminate NullPointerExceptions.

The Billion-Dollar Mistake

In Java, any variable can be null, causing a NullPointerException (NPE) at runtime — one of the most common crashes in Android apps.

Tony Hoare, who invented null, called it his billion-dollar mistake.

Kotlin eliminates NPEs at compile time with its null safety system.

Nullable vs Non-Nullable

In Kotlin, types are non-nullable by default. To allow null, add ? to the type:

  • String — never null, guaranteed
  • String? — can be null

The compiler enforces this — it won't let you assign null to a non-nullable type.

All lessons in this course

  1. Null Safety
  2. Classes & Objects
  3. Data Classes & Sealed Classes
  4. Extension Functions & Higher-Order Functions
← Back to Android Academy