jeudi 25 juillet 2019

Why is declaredFields including $change and serialVersionUID

In my android project I'm trying to loop through all the fields of a class using reflection, however, the result of declaredFields includes two unexpected fields, $change and serialVersionUID which aren't defined in the class

This is in an android project using a Kotlin data class. I've tried looking up the two fields in question and have seen that serialVersionUID seems to relate to classes which extend serialisable (https://stackoverflow.com/a/285809/8023278), the class in question doesn't implement serialisable though and I can't find any details about $change.

data class MyClass(
        @field:Json(name = "Id") var id: String
)

// then in some other class/method
MyClass::class.java.declaredFields.forEach { 
  // do something. 
  Log.d("", it.name)
}

I would expect only id to be logged however I actually get id, $change and serialVersionUID.





Aucun commentaire:

Enregistrer un commentaire