Order of Fields returned by Class.getFields()

后端 未结 4 1149
后悔当初
后悔当初 2021-02-19 07:06

Javadoc for Class.getFields() say: \"The elements in the array returned are not sorted and are not in any particular order.\"

Any hints on how the order act

4条回答
  •  天涯浪人
    2021-02-19 07:37

    It should be stable, and for Oracle's JVM its the order they are declared, but you should not rely on this.

    You should base lookup on the field's name (and possibly declaring class) rather than position.

提交回复
热议问题