Reflection getField() order

F

feng.hong

Does the Java language guarantee the order that the fields are returned
from getField()? It would be nice if the order that they are declared
in the classm is the order that getField() returns.(it is the case from
my sample test). However, is it garanteed? is there optimization that
would change the order?

Thanks.
 
J

John C. Bollinger

Does the Java language guarantee the order that the fields are returned
from getField()? It would be nice if the order that they are declared
in the classm is the order that getField() returns.(it is the case from
my sample test). However, is it garanteed? is there optimization that
would change the order?

I presume you are talking about method Class.getFields(). From its
Javadocs: "The elements in the array returned are not sorted and are not
in any particular order." Thus no, the order is explicitly *not*
guaranteed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top