Is there a Kotlin-specific way to load a Kotlin cl...
# getting-started
k
Is there a Kotlin-specific way to load a Kotlin class based on its fully qualified name and then call its default constructor?
Class.forName
+
Class.getConstructor
+
Constructor.newInstance
, but maybe something that starts with
KClass
?
p
Looks like Java reflection is the only way (for now): https://youtrack.jetbrains.com/issue/KT-10440
e
depends on what you're after, but
Copy code
Class.forName(name).kotlin.createInstance()
will work when there's a no-args constructor
1