To cast from one type to another, Kotlin uses the as keyword. Here’s how you would cast Any type to an Int type:
fun casting(any: Any) {
val num = any as Int
}
During runtime, before casting, the JVM will check if the source type can be cast to target type. If not, ClassCastException will be thrown.