What is the output?
fun lenOrZero(s: String?): Int {
return s?.length ?: 0
}
fun main() {
println(lenOrZero("kotlin"))
println(lenOrZero(null))
}
Try it in the online Kotlin Playground →
[spoiler title="Solution"]
Answer:
6 0
Explanation:
The safe call returns null for a null string, then ?: supplies 0.
[/spoiler]