← Kotlin Programming learning path
Kotlin Programming · Module 3 of 10

Null safety

Avoid NullPointerExceptions with Kotlin's type system.

📖 Key ideas

  1. Types are non-null by default: String cannot be null.
  2. Nullable types use ?: String?.
  3. Safe call: name?.length.
  4. Elvis operator: name ?: "Guest".
  5. !! forces non-null and may throw; avoid it.
💡 Real-life example: Null safety is a guard who checks every box for content before you lift it.
String?Nullable string
?.Safe call operator
?:Elvis default operator
!!Not-null assertion