Last active
July 10, 2020 15:26
-
-
Save zeroarst/288dfecb7523ad126432665f59509839 to your computer and use it in GitHub Desktop.
Chaining Kotlin Type Casting and following execution together!! (1)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// add this !! | |
infix fun <T, R> T?.then(block: T.() -> R): R? = this?.block() | |
abstract class Animal | |
class Cat : Animal() { | |
fun say() = "meow" | |
} | |
fun main() { | |
val myCat: Animal = Cat() | |
myCat as? Cat then { println(say()) } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment