Kotlin: smart casts

Example:

fun length(any: Any): Int? { if (any is String) { return any.length } return null }
Kotlin's smart casts eliminate explicit type casting.

Solution:

print(length("Hello")) // Outputs: 5

Beginner's Guide to Kotlin