Is it possible to create instance of class with reflection?
data class Person(name: String, age: Int)
If so, can anyone suggest me the code of how to create such a class programmatically?
Is it possible to create instance of class with reflection?
data class Person(name: String, age: Int)
If so, can anyone suggest me the code of how to create such a class programmatically?
Right now you can do it only using Java reflection, e.g.:
data class Person(name: String, age: Int)
fun main(args: Array<String>) {
val klass = javaClass<Person>()
val person = klass.newInstance()
}
Kotlin’s own reflection is work in progress, stay tuned.