is it possible in Kotlin to have a function that t...
# reflect
c
is it possible in Kotlin to have a function that take a reified type and do a
is
check on
reified T : Any
at runtime?
d
Yes.
inline fun <reified T> foo(value: Any?) = value is T
works fine.
c
what if I want to do something like
inline fun <reified T> foo() = T is Bar
. I know that is wrong. But is there a way to make it right?
d
T::class.isSubclassOf(Bar::class)
or (no Kotlin reflection, but JVM only):
Bar::class.java.isAssignableFrom(T::class.java)
💯 1
c
ah ha, you are my hero!