Android ● ● ○ Kotlin 2.0

Kodebits Day 83: Smart Cast

Aug 28 2026
Practice type checks with a short kotlin challenge.

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]


Further Reading