Kotlin types are non‑null by default. To allow null you mark a type with ?. Safe calls (?.), the Elvis operator (?:), and scope functions like let help handle nullable values without NPEs. !! forces a non‑null assertion and can throw.
val name: String? = null
val length = name?.length ?: 0
println(length)Expanding on the short answer — what usually matters in practice:
Here’s an additional example (building on the short answer):
val name: String? = null
val length = name?.length ?: 0
println(length)