jeudi 19 octobre 2017

Kotlin: Compare property values of different target objects with(out) reflection

I want to compare values between multiple instances of a data class so that I know which value changed:

data class A(val name : String)
val firstA = A("hello")
val secondA = A("you")

if (secondA.name.changed(firstA)) {
   // Do something
}

Can I somehow access the property function of .name and execute it on another target value (in this example on firstA) without explicitly defining it? Can delegates help here or how do I solve this with and without reflection?





Aucun commentaire:

Enregistrer un commentaire