← Kotlin Programming learning pathKotlin Programming · Module 3 of 10
Null safety
Avoid NullPointerExceptions with Kotlin's type system.
📖 Key ideas
- Types are non-null by default: String cannot be null.
- Nullable types use ?: String?.
- Safe call: name?.length.
- Elvis operator: name ?: "Guest".
- !! 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