I guess Kotlin gives me plenty of tools here to avoid the explicit cast, so I'll use that even if bugs me aesthetically (I wish I cared less about this sort of things)
r
Rob Elliot
05/01/2024, 12:54 PM
I probably overuse extension functions for parenthesis avoidance, but you can of course do:
Copy code
fun Any.asFoo() = this as? Foo
fun Bar.asBarWithBaz() = this as? BarWithBaz
this.asFoo()?.bar?.asBarWithBaz()?.baz ?: someOtherBaz
y
y
05/01/2024, 12:57 PM
@Rob Elliot please see what I linked, this is "unsafe" so I stopped using functions like this