Partager via


Class.GetMethods Method

Definition

Returns an array containing Method objects reflecting all the public methods of the class or interface represented by this Class object, including those declared by the class or interface and those inherited from superclasses and superinterfaces.

[Android.Runtime.Register("getMethods", "()[Ljava/lang/reflect/Method;", "")]
public Java.Lang.Reflect.Method[] GetMethods ();
[<Android.Runtime.Register("getMethods", "()[Ljava/lang/reflect/Method;", "")>]
member this.GetMethods : unit -> Java.Lang.Reflect.Method[]

Returns

Method[]

the array of Method objects representing the public methods of this class

Attributes

Remarks

Returns an array containing Method objects reflecting all the public methods of the class or interface represented by this Class object, including those declared by the class or interface and those inherited from superclasses and superinterfaces.

If this Class object represents an array type, then the returned array has a Method object for each of the public methods inherited by the array type from Object. It does not contain a Method object for clone().

If this Class object represents an interface then the returned array does not contain any implicitly declared methods from Object. Therefore, if no methods are explicitly declared in this interface or any of its superinterfaces then the returned array has length 0. (Note that a Class object which represents a class always has public methods, inherited from Object.)

The returned array never contains methods with names "<init>" or "<clinit>".

The elements in the returned array are not sorted and are not in any particular order.

Generally, the result is computed as with the following 4 step algorithm. Let C be the class or interface represented by this Class object: <ol> <li> A union of methods is composed of: <ol type="a"> <li> C's declared public instance and static methods as returned by #getDeclaredMethods() and filtered to include only public methods.</li> <li> If C is a class other than Object, then include the result of invoking this algorithm recursively on the superclass of C.</li> <li> Include the results of invoking this algorithm recursively on all direct superinterfaces of C, but include only instance methods.</li> </ol></li> <li> Union from step 1 is partitioned into subsets of methods with same signature (name, parameter types) and return type.</li> <li> Within each such subset only the most specific methods are selected. Let method M be a method from a set of methods with same signature and return type. M is most specific if there is no such method N != M from the same set, such that N is more specific than M. N is more specific than M if: <ol type="a"> <li> N is declared by a class and M is declared by an interface; or</li> <li> N and M are both declared by classes or both by interfaces and N's declaring type is the same as or a subtype of M's declaring type (clearly, if M's and N's declaring types are the same type, then M and N are the same method).</li> </ol></li> <li> The result of this algorithm is the union of all selected methods from step 3.</li> </ol>

Added in 1.1.

Java documentation for java.lang.Class.getMethods().

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

See also