• Post Reply Bookmark Topic Watch Topic
  • New Topic

order of methods returned by Class.getMethods  RSS feed

 
Kevin Davies
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is order that the methods are returned by java.lang.Class.getMethods()? The first time a compile a class and use reflection on it, the methods appear to return in the order that they were defined in the source file. But if change the order and recompile, the order doesn't seem to change. What is the deal?
 
Ryan McGuire
Ranch Hand
Posts: 1143
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sun's 1.4.2 API javadoc says this:


public Method[] getMethods()
throws SecurityException

Returns an array containing Method objects reflecting all the public member methods of the class or interface represented by this Class object, including those declared by the class or interface and and those inherited from superclasses and superinterfaces. The elements in the array returned are not sorted and are not in any particular order. This method returns an array of length 0 if this Class object represents a class or interface that has no public member methods, or if this Class object represents an array class, primitive type, or void.


Relying on the order of methods always coming out in the order they did during testing on a particular machine, using a particular JVM, during a particular phase of the moon, etc. is a bad idea indeed.
[ July 22, 2005: Message edited by: Ryan McGuire ]
 
Kevin Davies
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, is there any way to find out the order that methods where defined in the source?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Only by parsing the source, I think.

Why do you want to know?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!