https://kotlinlang.org logo
#announcements
Title
# announcements
i

igor.wojda

07/06/2019, 1:43 PM
Assuming we have such method
Copy code
putData(property: KProperty1<out Any?, Any?>, value: Any?) { }
Is there any way to check is
property
is of the same type as
value
?
d

Dominaezzz

07/06/2019, 1:54 PM
At run time or compile time?
i

igor.wojda

07/06/2019, 1:57 PM
Runtime
l

louiscad

07/06/2019, 5:12 PM
Depends if you want to accept subclasses or consider them as not same type.
Also depends on if you support JVM only or multiplatform
d

Dico

07/06/2019, 5:12 PM
value != null && property.type.classifier!!.java.isAssignableFrom(value.javaClass)
i

igor.wojda

07/07/2019, 3:17 PM
@louiscad yah I want to accept subclasses and target JVM. Do you have other suggestion than @Dico?
l

louiscad

07/07/2019, 3:28 PM
His solution seems a good one. Check for yourself it works the way you expect. It it doesn't, you still have a good starting point @igor.wojda
👍 1