What is the output?
fun main() {
val x: Any = "Kotlin"
if (x is String) {
println(x.length)
}
}
Try it in the online Kotlin Playground →
[spoiler title="Solution"]
Answer:
6
Explanation:
Smart casts automatically convert types after an is check. Inside the if block, x is treated as String, so .length is accessible without explicit casting.
[/spoiler]