java - Does Class.getDeclaredFields() return members in a consistent order? -
the documentation describes method as:
the elements in array returned not sorted , not in particular order
however not sure if implies order not consistent each time application invokes routine.
i looking way pair unique id each field found - needs consistent next time application run, i.e continuously generate same id.
i wanting iterate on each field found , increment counter per each element iterated. assign id of particular element whatever counter equal to, these 'ids' aren't consistent though if fields not returned in consistent order.
the order not required stable across runs. however, field's hashcode()
value defined stable (it's documented field.getdeclaringclass().getname().hashcode() ^ field.getname().hashcode()
), may able use id, understanding hash code not guaranteed unique.
alternatively, may sort results returned getdeclaredfields()
yourself, using whatever sorting criteria suits you.
Comments
Post a Comment