Casting

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.111.179