aicas logo Jamaica 3.4 release 8

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

Method enables reflection access to Java methods.


Field Summary
 
Fields inherited from interface java.lang.reflect.Member
DECLARED, PUBLIC
 
Method Summary
 boolean equals(Object obj)
          equals compares two methods.
<T extends Annotation>
T
getAnnotation(Class<T> annotationClass)
          Returns this element's annotation for the specified type if such an annotation is present, else null.
 Annotation[] getDeclaredAnnotations()
          Returns all annotations that are directly present on this element.
 Class<?> getDeclaringClass()
          getDeclaringClass returns the class this method was declared in.
 Object getDefaultValue()
          Returns the default value for the annotation member represented by this Method instance.
 Class<?>[] getExceptionTypes()
          getExceptionTypes returns an array of all declared exceptions of this method.
 Type[] getGenericExceptionTypes()
          getGenericExceptionTypes NYI: COMMENT: JDK 1.5 method description
 Type[] getGenericParameterTypes()
          getGenericParameterTypes NYI: COMMENT: JDK 1.5 method description
 Type getGenericReturnType()
          getGenericReturnType NYI: COMMENT: JDK 1.5 method description
 int getModifiers()
          getModifiers returns the set of modifiers set for this method.
 String getName()
          getName returns the name of this method.
 Annotation[][] getParameterAnnotations()
          Returns an array of arrays that represent the annotations on the formal parameters, in declaration order, of the method represented by this Method object.
 Class<?>[] getParameterTypes()
          getParameterTypes returns an array with the type of all the parameters of this method.
 Class<?> getReturnType()
          getReturnType returns the return type of this method.
 TypeVariable<?>[] getTypeParameters()
          getTypeParameters NYI: COMMENT: JDK 1.5 method description
 int hashCode()
          hashCode returns a hash code for this field
 Object invoke(Object obj, Object... args)
          invoke executes this method with the given arguments
 boolean isBridge()
          Returns true if this method is a bridge method; returns false otherwise.
 boolean isSynthetic()
          isSynthetic NYI: COMMENT: JDK 1.5 method description
 boolean isVarArgs()
          isVarArgs NYI: COMMENT: JDK 1.5 method description
 String toGenericString()
          toGenericString NYI: COMMENT: JDK 1.5 method description
 String toString()
          toString converts this method into a string such as "public int java.lang.Integer.intValue()"
 
Methods inherited from class java.lang.reflect.AccessibleObject
getAnnotations, isAccessible, isAnnotationPresent, setAccessible, setAccessible
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

getDeclaringClass

public Class<?> getDeclaringClass()
getDeclaringClass returns the class this method was declared in.

Specified by:
getDeclaringClass in interface Member
Returns:
The class declaring this method.
See Also:
Member.getDeclaringClass()

getName

public String getName()
getName returns the name of this method.

Specified by:
getName in interface Member
Returns:
the name as a java string.

getModifiers

public int getModifiers()
getModifiers returns the set of modifiers set for this method.

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

getReturnType

public Class<?> getReturnType()
getReturnType returns the return type of this method.

Returns:
the type, either a Java class, an array type, a primitive type such as Integer.TYPE or Void.tYPE.

getParameterTypes

public Class<?>[] getParameterTypes()
getParameterTypes returns an array with the type of all the parameters of this method.

Returns:
an array of all parameters of this method.

getExceptionTypes

public Class<?>[] getExceptionTypes()
getExceptionTypes returns an array of all declared exceptions of this method.

Returns:
array of declared exceptions, never null.

equals

public boolean equals(Object obj)
equals compares two methods.

Overrides:
equals in class Object
Parameters:
obj - another method
Returns:
true iff obj is a method with the same declaringClass(), the same name, equal getParameterTypes() arrays and equal return type compared to this.

hashCode

public int hashCode()
hashCode returns a hash code for this field

Overrides:
hashCode in class Object
Returns:
getDeclaringClass().getName().hashCode() ^ getName().hashCode()

toString

public String toString()
toString converts this method into a string such as "public int java.lang.Integer.intValue()"

Overrides:
toString in class Object
Returns:
a string representation of this method.

invoke

public Object invoke(Object obj,
                     Object... args)
              throws IllegalAccessException,
                     IllegalArgumentException,
                     InvocationTargetException
invoke executes this method with the given arguments

Parameters:
obj - the target object of this method if this is an instance method. Ignored in case of a static method.
args - the arguments to be passed to this method.
Returns:
the, possibly boxed return value of this method, null for a method with void as return type.
Throws:
NullPointerException - if this is an instance method and obj is null.
IllegalAccessException - if the caller does not have the right to access this method.
InvocationTargetException - if this method returns with an exception, this exception is replaced by an instance of InvocationTargetException.
ExceptionInInitializerError - if this is a static method and initialization of the declaring class failed.
IllegalArgumentException

getTypeParameters

public TypeVariable<?>[] getTypeParameters()
getTypeParameters

NYI: COMMENT: JDK 1.5 method description

Specified by:
getTypeParameters in interface GenericDeclaration
Returns:
the parameter types for the method this object represents
Since:
1.5

getGenericReturnType

public Type getGenericReturnType()
getGenericReturnType

NYI: COMMENT: JDK 1.5 method description

Returns:
a Type object that represents the formal return type of the underlying method
Since:
1.5

getGenericExceptionTypes

public Type[] getGenericExceptionTypes()
getGenericExceptionTypes

NYI: COMMENT: JDK 1.5 method description

Returns:
an array of Types that represent the exception types thrown by the underlying method
Since:
1.5

getGenericParameterTypes

public Type[] getGenericParameterTypes()
getGenericParameterTypes

NYI: COMMENT: JDK 1.5 method description

Returns:
an array of Types that represent the formal parameter types of the underlying method, in declaration order
Since:
1.5

toGenericString

public String toGenericString()
toGenericString

NYI: COMMENT: JDK 1.5 method description

Returns:
a string describing this Method, include type parameters
Since:
1.5

isSynthetic

public boolean isSynthetic()
isSynthetic

NYI: COMMENT: JDK 1.5 method description

Specified by:
isSynthetic in interface Member
Returns:
true if and only if this method is a synthetic method as defined by the Java Language Specification.
Since:
1.5

isVarArgs

public boolean isVarArgs()
isVarArgs

NYI: COMMENT: JDK 1.5 method description

Returns:
true if an only if this method was declared to take a variable number of arguments.
Since:
1.5

isBridge

public boolean isBridge()
Returns true if this method is a bridge method; returns false otherwise.

Returns:
true if and only if this method is a bridge method as defined by the Java Language Specification.
Since:
1.5

getAnnotation

public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
Description copied from interface: AnnotatedElement
Returns this element's annotation for the specified type if such an annotation is present, else null.

Specified by:
getAnnotation in interface AnnotatedElement
Overrides:
getAnnotation in class AccessibleObject
Parameters:
annotationClass - the Class object corresponding to the annotation type
Returns:
this element's annotation for the specified annotation type if present on this element, else null
Throws:
NullPointerException - if the given annotation class is null
Since:
1.5

getDeclaredAnnotations

public Annotation[] getDeclaredAnnotations()
Description copied from interface: AnnotatedElement
Returns all annotations that are directly present on this element. Unlike the other methods in this interface, this method ignores inherited annotations. (Returns an array of length zero if no annotations are directly present on this element.) The caller of this method is free to modify the returned array; it will have no effect on the arrays returned to other callers.

Specified by:
getDeclaredAnnotations in interface AnnotatedElement
Overrides:
getDeclaredAnnotations in class AccessibleObject
Returns:
All annotations directly present on this element
Since:
1.5

getParameterAnnotations

public Annotation[][] getParameterAnnotations()
Returns an array of arrays that represent the annotations on the formal parameters, in declaration order, of the method represented by this Method object. (Returns an array of length zero if the underlying method is parameterless. If the method has one or more parameters, a nested array of length zero is returned for each parameter with no annotations.) The annotation objects contained in the returned arrays are serializable. The caller of this method is free to modify the returned arrays; it will have no effect on the arrays returned to other callers.

Returns:
an array of arrays that represent the annotations on the formal parameters, in declaration order, of the method represented by this Method object
Since:
1.5

getDefaultValue

public Object getDefaultValue()
Returns the default value for the annotation member represented by this Method instance. If the member is of a primitive type, an instance of the corresponding wrapper type is returned. Returns null if no default is associated with the member, or if the method instance does not represent a declared member of an annotation type.

Returns:
the default value for the annotation member represented by this Method instance.
Throws:
TypeNotPresentException - if the annotation is of type Class and no definition can be found for the default class value.
Since:
1.5

aicas logo Jamaica 3.4 release 8

aicas GmbH, Karlsruhe - Germany    www.aicas.com
Copyright 2001-2009 aicas GmbH. All Rights Reserved.