Build 1.0_r1(from source)

java.lang.reflect
Class Method

java.lang.Object
  extended by java.lang.reflect.AccessibleObject
      extended by java.lang.reflect.Method
All Implemented Interfaces:
AnnotatedElement, GenericDeclaration, Member

public final class Method
extends AccessibleObject
implements GenericDeclaration, Member

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


Field Summary
 
Fields inherited from class java.lang.reflect.AccessibleObject
flag, trans
 
Fields inherited from interface java.lang.reflect.Member
DECLARED, PUBLIC
 
Constructor Summary
Method(Method orig)
          Construct a clone of the given instance.
 
Method Summary
 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.
(package private)  String getSignatureAttribute()
          Gets the Signature attribute for this instance.
 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.
(package private) static Annotation[][] noAnnotations(int size)
          Creates an array of empty Annotation arrays.
 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
appendArrayGenericType, appendArrayType, appendArrayType, appendGenericType, appendSimpleType, getAnnotation, getAnnotations, getClassSignatureAttribute, getReflectionAccess, getSignature, isAccessible, isAnnotationPresent, setAccessible, setAccessible, setAccessibleNoCheck, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Method

Method(Method orig)
Construct a clone of the given instance.

Parameters:
orig - non-null; the original instance to clone
Method Detail

getTypeParameters

public TypeVariable<Method>[] getTypeParameters()
Description copied from interface: GenericDeclaration
Returns the generic declared types in declaration order. If there are no generic types this method returns a zero length array.

Specified by:
getTypeParameters in interface GenericDeclaration
Returns:
array of generic declared type variables.

getSignatureAttribute

String getSignatureAttribute()
Gets the Signature attribute for this instance. Returns null if not found.

Overrides:
getSignatureAttribute in class AccessibleObject

toGenericString

public String toGenericString()

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

Returns:
An instance of String.
Since:
1.5

getGenericParameterTypes

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.
Since:
1.5

getGenericExceptionTypes

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.
Since:
1.5

getGenericReturnType

public Type getGenericReturnType()

Gets the return type as a Type instance.

Returns:
A Type instance.
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.
Since:
1.5

getDeclaredAnnotations

public Annotation[] getDeclaredAnnotations()
Description copied from interface: AnnotatedElement
Gets all Annotations that are explicitly declared by this element (not inherited).

Specified by:
getDeclaredAnnotations in interface AnnotatedElement
Overrides:
getDeclaredAnnotations in class AccessibleObject
Returns:
An array of Annotations, which may be empty, but never null.

noAnnotations

static Annotation[][] noAnnotations(int size)
Creates an array of empty Annotation arrays.


getParameterAnnotations

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:
An array of arrays of Annotation instances.
Since:
1.5

isVarArgs

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.
Since:
1.5

isBridge

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.
Since:
1.5

isSynthetic

public boolean isSynthetic()

Indicates whether or not this method is synthetic.

Specified by:
isSynthetic in interface Member
Returns:
A value of true if this method is synthetic, otherwise false.
Since:
1.5

getDefaultValue

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.
Since:
1.5

equals

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.

Overrides:
equals in class Object
Parameters:
object - the object to compare
Returns:
true if the specified object is equal to this Method, false otherwise
See Also:
hashCode()

getDeclaringClass

public Class<?> getDeclaringClass()
Return the Class associated with the class that defined this method.

Specified by:
getDeclaringClass in interface Member
Returns:
the declaring class

getExceptionTypes

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

getModifiers

public int getModifiers()
Return the modifiers for the modeled method. The Modifier class should be used to decode the result.

Specified by:
getModifiers in interface Member
Returns:
the modifiers
See Also:
Modifier

getName

public String getName()
Return the name of the modeled method.

Specified by:
getName in interface Member
Returns:
the name

getParameterTypes

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

getReturnType

public Class<?> getReturnType()
Return the Class associated with the return type of this method.

Returns:
the return type

hashCode

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.

Overrides:
hashCode in class Object
Returns:
the receiver's hash
See Also:
equals(java.lang.Object)

invoke

public Object invoke(Object receiver,
                     Object... args)
              throws IllegalAccessException,
                     IllegalArgumentException,
                     InvocationTargetException
Return the result of dynamically invoking the modeled method. This reproduces the effect of receiver.methodName(arg1, arg2, ... , argN) This method performs the following:

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:
AccessibleObject

toString

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

Overrides:
toString in class Object
Returns:
a printable representation for the receiver

Build 1.0_r1(from source)

Please submit a feedback, bug or feature