y
03/25/2023, 12:24 PMas?
as a function? foo.tryAs(String)
= foo as? String
Sam
03/25/2023, 12:31 PMinline fun <reified T> Any.tryAs(): T? = this as? T
The angle brackets specify a type parameter. You call it like this.
foo.tryAs<String>()
For more explanation read this section of the docs: https://kotlinlang.org/docs/inline-functions.html#reified-type-parametersy
03/25/2023, 12:34 PMPaul Griffith
03/27/2023, 3:50 PMfoo::class.safeCast(bar)
(from an instance of foo)