Is it possible to use instance checks (i.e. x is String checks in Kotlin) when using Class.forName()? I want to apply this to a class that is only available at runtime, not at compile time.
MWE:
val x = "banana"
val specialClass = Class.forName("org.company.specialclass.at.runtime")
x is specialClass
However, I get unresolved reference on specialClass. Any ideas?
The function isInstance may help:
Class.forName("java.lang.String").isInstance("txt") //true
Here you can find the documentation for isInstance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With