Create an instance of class with reflection


#1

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?


#2

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.