jeudi 1 juin 2017

How to set delegated property value by reflection in kotlin?

my entity class:

class User : ActiveRecord<User>() {

    var name by Column(String.javaClass);

    var id by Column(Int.javaClass);

}

now i want to set name value by refelection:

  var clazz = User().javaClass

  var record = clazz.newInstance()

  var field = record.getDeclaredField(it + "$" + "delegate")

  field.set(record,"aa")

then error :

entity.Column field ActiveRecord4k.User.name$delegate to java.lang.String

how to do this? ty!





Aucun commentaire:

Enregistrer un commentaire