It is said on the docs of Class.getDeclaredFields()
that
The elements in the returned array are not sorted and are not in any particular order.
But I found that the results are actually sorted in perfect alphabetical order instead of the declration order. So what's going on? My JDK version is 1.8.
PS: I wonder this because I am now implementing a way of object serialization relying on the declaration order of the declared fields, which is not affected by code obfuscation. Is there any better idea to do this?