Join Slack
Powered by
Hi. If I have a KClass<T>, how do I safely ...
# reflect
n
natpryce
11/24/2017, 3:10 PM
Hi. If I have a KClass<T>, how do I safely cast a value of type Any to a value of type T? I’m looking for a dynamic equivalent to the
as?
operator.
u
udalov
11/30/2017, 4:11 PM
There's
KClass.cast
, but it's JVM-only
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.reflect.full/cast.html
n
natpryce
11/30/2017, 8:48 PM
Yes, I should say… this is a multiplatform project.
natpryce
11/30/2017, 8:49 PM
For some reason, KClass.cast is not available in JavaScript, although using a reified type parameter with
as?
works.
3
Views
Open in Slack
Previous
Next