KotlinQuickReference
KotlinQuickReference copied to clipboard
`as` and `as?`
Need some coverage of as
and as?
, probably as a separate chapter (at least initially).
The start of some code:
fun main(args: Array<String>) {
val d = Dog()
val c = Cat()
val x = d as Dog
//ClassCastException: Cat cannot be cast to Dog
val y = c as Dog
}
interface Pet
class Dog : Pet
class Cat : Pet