Fundamentals15 / 15
Up next

Nullable types

fun main() {
    // a nullable type is spelled with a trailing ?
    val maybe: String? = null
    // ?. short-circuits, ?: supplies a fallback
    println(maybe?.length ?: -1)
}
What you're solving

mark null with ? and default with ?: