What is the output?
fun main() {
var b: String? = "abc"
b = null
val l = b?.length ?: -1
println(l)
b = "kotlin"
println(b?.length)
}
Try it in the online Kotlin Playground →
[spoiler title="Solution"]
Answer:
-1 6
Explanation:
The Elvis operator ?: returns the right side if the left is null. The first print, b is null, the second it has a value.
[/spoiler]