Skip to content
RED SAG Skills
mediumStudy question · answer published in Kotlin interview questions, so no pointsandroidkotlinnull-safety

Smart cast refused

Why does this fail to compile, and what is a common fix?

class User { var name: String? = null }

fun show(user: User) {
    if (user.name != null) {
        println(user.name.length)
    }
}
Choose one answer

Discussion 0

Join free to post in the discussion.

Related questions