jeudi 27 juillet 2017

Android getDeclaredFields() return a disorder result

I declared a class like this:

public class Bean {
    public int id;
    public String name;
    public int age;
}

I use Bean.class.getDeclaredFields() to get the fields of Bean.class. The standard JRE on PC returned

  • id,
  • name,
  • age

fields. But the same code running on Android (4.1.2 Dalvik JVM), the result fields order is

  • name,
  • age,
  • id.

I noted that the implementation of getDelclaredFields() in Android is changed. It may be impossible to change the behavior. But I still want to known that how to get the ordered fields result.





Aucun commentaire:

Enregistrer un commentaire