jeudi 18 juillet 2019

Set property by string in Kotlin using reflection?

I have an object:

class User {
  var id: String? = null
  var name: String? = null
}

and list of pairs:

val fieldsToChange = listOf<Pair<String, String>>(Pair("name", "foo"), Pair("id", "bar"))

I would like to iterate trough list of pairs and set appropriate values for given properties using reflection.





Aucun commentaire:

Enregistrer un commentaire