Reflection getField() order

Discussion in 'Java' started by feng.hong@gmail.com, Jun 13, 2005.

  1. Guest

    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.
     
    , Jun 13, 2005
    #1
    1. Advertising

  2. wrote:

    > 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.

    --
    John Bollinger
     
    John C. Bollinger, Jun 13, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Soren Kuula
    Replies:
    2
    Views:
    541
    Soren Kuula
    Feb 1, 2004
  2. David Portabella
    Replies:
    6
    Views:
    1,280
  3. cspoh
    Replies:
    0
    Views:
    267
    cspoh
    Jul 31, 2003
  4. Stephan Kämper
    Replies:
    2
    Views:
    257
    Stephan Kämper
    Jan 18, 2004
  5. Greg Willits

    Reflection method name order

    Greg Willits, Nov 26, 2008, in forum: Ruby
    Replies:
    1
    Views:
    127
    Stefano Crocco
    Nov 26, 2008
Loading...

Share This Page