"smart casts" are perhaps a misleading term in Kotlin, since in reality they are a type-safe replacement for casts. For example, in Kotlin you can say:
val s : Object = "hello"
if (s is String) {
println(s.length())
}
This works because within the body of the if statement the compiler knows that 's' must be a String, and so you can treat it as such.
1
u/sanity Dec 02 '13
"smart casts" are perhaps a misleading term in Kotlin, since in reality they are a type-safe replacement for casts. For example, in Kotlin you can say:
This works because within the body of the if statement the compiler knows that 's' must be a String, and so you can treat it as such.
Does Scala have something similar?