Kotlin - Null Safety
What will be the output of this Kotlin code?
var text: String? = null println(text?.length ?: "No length")
var text: String? = null println(text?.length ?: "No length")
text?.length safely accesses length if text is not null; else returns null. The Elvis operator ?: provides "No length" if left side is null.text is null, text?.length is null, so the expression prints "No length".15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions