Kotlin: how do i handle null safety properly?

Example:

val name: String = null  // Compilation error
Solution:

val name: String? = null  // Correctly using nullable type
In Kotlin, types are non-nullable by default. If you want a variable to hold a null value, you must explicitly declare its type as nullable using `?`.

Beginner's Guide to Kotlin