Android
java.lang.reflect
public final class

java.lang.reflect.Method

java.lang.Object
java.lang.reflect.AccessibleObject AnnotatedElement
java.lang.reflect.Method GenericDeclaration Member

This class models a method. Information about the method can be accessed, and the method can be invoked dynamically.

Summary

Constants inherited from interface java.lang.reflect.Member

Public Methods

          boolean  equals(Object object)
Compares the specified object to this Method and determines if they are equal.
          Annotation[]  getDeclaredAnnotations()
Gets all Annotations that are explicitly declared by this element (not inherited).
          Class<?>  getDeclaringClass()
Return the Class associated with the class that defined this method.
          Object  getDefaultValue()

Gets the default value for the annotation member represented by this method.

          Class[]<?>  getExceptionTypes()
Return an array of the Class objects associated with the exceptions declared to be thrown by this method.
          Type[]  getGenericExceptionTypes()

Gets the exception types as an array of Type instances.

          Type[]  getGenericParameterTypes()

Gets the parameter types as an array of Type instances, in declaration order.

          Type  getGenericReturnType()

Gets the return type as a Type instance.

          int  getModifiers()
Return the modifiers for the modeled method.
          String  getName()
Return the name of the modeled method.
          Annotation[][]  getParameterAnnotations()

Gets an array of arrays that represent the annotations of the formal parameters of this method.

          Class[]<?>  getParameterTypes()
Return an array of the Class objects associated with the parameter types of this method.
          Class<?>  getReturnType()
Return the Class associated with the return type of this method.
          TypeVariable[]<Method getTypeParameters()
Returns the generic declared types in declaration order.
          int  hashCode()
Returns an integer hash code for the receiver.
          Object  invoke(Object receiver, Object[] args)
Return the result of dynamically invoking the modeled method.
          boolean  isBridge()

Indicates whether or not this method is a bridge.

          boolean  isSynthetic()

Indicates whether or not this method is synthetic.

          boolean  isVarArgs()

Indicates whether or not this method takes a variable number argument.

          String  toGenericString()

Returns the String representation of the method's declaration, including the type parameters.

          String  toString()
Returns a string containing a concise, human-readable description of the receiver.
Methods inherited from class java.lang.reflect.AccessibleObject
Methods inherited from class java.lang.Object
Methods inherited from interface java.lang.reflect.AnnotatedElement
Methods inherited from interface java.lang.reflect.GenericDeclaration
Methods inherited from interface java.lang.reflect.Member

Details

Public Methods

public boolean equals(Object object)

Compares the specified object to this Method and determines if they are equal. The object must be an instance of Method with the same defining class and parameter types.

Parameters

object the object to compare

Returns

  • true if the specified object is equal to this Method, false otherwise

See Also

public Annotation[] getDeclaredAnnotations()

Gets all Annotations that are explicitly declared by this element (not inherited).

public Class<?> getDeclaringClass()

Return the Class associated with the class that defined this method.

Returns

  • the declaring class

public Object getDefaultValue()

Gets the default value for the annotation member represented by this method.

Returns

  • The default value or null if none.

Throws

TypeNotPresentException if the annotation is of type Class and no definition can be found.

public Class[]<?> getExceptionTypes()

Return an array of the Class objects associated with the exceptions declared to be thrown by this method. If the method was not declared to throw any exceptions, the array returned will be empty.

Returns

  • the declared exception classes

public Type[] getGenericExceptionTypes()

Gets the exception types as an array of Type instances. If the method has no declared exceptions, then an empty array is returned.

Returns

  • An array of Type instances.

Throws

GenericSignatureFormatError if the generic method signature is invalid.
TypeNotPresentException if the component type points to a missing type.
MalformedParameterizedTypeException if the component type points to a type that can't be instantiated for some reason.

public Type[] getGenericParameterTypes()

Gets the parameter types as an array of Type instances, in declaration order. If the method has no parameters, then an empty array is returned.

Returns

  • An array of Type instances.

Throws

GenericSignatureFormatError if the generic method signature is invalid.
TypeNotPresentException if the component type points to a missing type.
MalformedParameterizedTypeException if the component type points to a type that can't be instantiated for some reason.

public Type getGenericReturnType()

Gets the return type as a Type instance.

Returns

Throws

GenericSignatureFormatError if the generic method signature is invalid.
TypeNotPresentException if the component type points to a missing type.
MalformedParameterizedTypeException if the component type points to a type that can't be instantiated for some reason.

public int getModifiers()

Return the modifiers for the modeled method. The Modifier class should be used to decode the result.

Returns

  • the modifiers

See Also

public String getName()

Return the name of the modeled method.

Returns

  • the name

public Annotation[][] getParameterAnnotations()

Gets an array of arrays that represent the annotations of the formal parameters of this method. If there are no parameters on this method, then an empty array is returned. If there are no annotations set, then and array of empty arrays is returned.

Returns

public Class[]<?> getParameterTypes()

Return an array of the Class objects associated with the parameter types of this method. If the method was declared with no parameters, the array returned will be empty.

Returns

  • the parameter types

public Class<?> getReturnType()

Return the Class associated with the return type of this method.

Returns

  • the return type

public TypeVariable[]<Method> getTypeParameters()

Returns the generic declared types in declaration order. If there are no generic types this method returns a zero length array.

public int hashCode()

Returns an integer hash code for the receiver. Objects which are equal return the same value for this method. The hash code for a Method is the hash code of the method's name.

Returns

  • the receiver's hash

See Also

public Object invoke(Object receiver, Object[] args)

Return the result of dynamically invoking the modeled method. This reproduces the effect of receiver.methodName(arg1, arg2, ... , argN) This method performs the following:
  • If the modeled method is static, the receiver argument is ignored.
  • Otherwise, if the receiver is null, a NullPointerException is thrown.
  • If the receiver is not an instance of the declaring class of the method, an IllegalArgumentException is thrown.
  • If this Method object is enforcing access control (see AccessibleObject) and the modeled method is not accessible from the current context, an IllegalAccessException is thrown.
  • If the number of arguments passed and the number of parameters do not match, an IllegalArgumentException is thrown.
  • For each argument passed:
    • If the corresponding parameter type is a base type, the argument is unwrapped. If the unwrapping fails, an IllegalArgumentException is thrown.
    • If the resulting argument cannot be converted to the parameter type via a widening conversion, an IllegalArgumentException is thrown.
  • If the modeled method is static, it is invoked directly. If it is non-static, the modeled method and the receiver are then used to perform a standard dynamic method lookup. The resulting method is then invoked.
  • If an exception is thrown during the invocation it is caught and wrapped in an InvocationTargetException. This exception is then thrown.
  • If the invocation completes normally, the return value is itself returned. If the method is declared to return a base type, the return value is first wrapped. If the return type is void, null is returned.

Parameters

receiver The object on which to call the modeled method
args the arguments to the method

Returns

  • the new, initialized, object

Throws

NullPointerException if the receiver is null for a non-static method
IllegalAccessException if the modeled method is not accessible
IllegalArgumentException if an incorrect number of arguments are passed, the receiver is incompatible with the declaring class, or an argument could not be converted by a widening conversion
InvocationTargetException if an exception was thrown by the invoked method

See Also

public boolean isBridge()

Indicates whether or not this method is a bridge.

Returns

  • A value of true if this method's a bridge, otherwise false.

public boolean isSynthetic()

Indicates whether or not this method is synthetic.

Returns

  • A value of true if this method is synthetic, otherwise false.

public boolean isVarArgs()

Indicates whether or not this method takes a variable number argument.

Returns

  • A value of true if a vararg is declare, otherwise false.

public String toGenericString()

Returns the String representation of the method's declaration, including the type parameters.

Returns

  • An instance of String.

public String toString()

Returns a string containing a concise, human-readable description of the receiver. The format of the string is modifiers (if any) return type declaring class name '.' method name '(' parameter types, separated by ',' ')' If the method throws exceptions, ' throws ' exception types, separated by ',' For example: public native Object java.lang.Method.invoke(Object,Object) throws IllegalAccessException,IllegalArgumentException,InvocationTargetException

Returns

  • a printable representation for the receiver
Copyright 2007 Google Inc. Build 0.9_r1-98467 - 14 Aug 2008 18:48