How do I dynamically instantiate `Person` having a...
# reflect
d
How do I dynamically instantiate
Person
having a map of constructor arguments?
Copy code
data class Person(val id: Int, val name: String, val age: Int?)
Copy code
val args = mapOf("id" to 1, "name" to "Alice")
val newPerson = ???
d
Find the constructor you want inside
KClass.constructors
then use
callBy
on that.
d
What if I have only
java.lang.Class
?
d
Convert to
KClass
using
jClassInstance.kotlin