public final class Method extends AbstractMethod implements GenericDeclaration, Member
| Modifier and Type | Field and Description |
|---|---|
static Comparator<Method> |
ORDER_BY_SIGNATURE
Orders methods by their name, parameters and return type.
|
accessFlags, artMethod, declaringClass, declaringClassOfOverriddenMethod, dexMethodIndex| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object other)
Returns true if
other has the same declaring class, name,
parameters and return type as this method. |
<A extends Annotation> |
getAnnotation(Class<A> annotationType)
Returns, for this element, the annotation with the specified type, or
null if no annotation with the specified type is present
(including inherited annotations). |
Annotation[] |
getAnnotations()
Returns, for this element, an array containing all annotations (including
inherited annotations).
|
Annotation[] |
getDeclaredAnnotations()
Returns, for this element, all annotations that are explicitly declared
(not inherited).
|
Class<?> |
getDeclaringClass()
Returns the class that declares this method.
|
Object |
getDefaultValue()
Returns the default value for the annotation member represented by this
method.
|
Class<?>[] |
getExceptionTypes()
Returns the exception types as an array of
Class instances. |
Type[] |
getGenericExceptionTypes()
Returns the exception types as an array of
Type instances. |
Type[] |
getGenericParameterTypes()
Returns the parameter types as an array of
Type instances, in
declaration order. |
Type |
getGenericReturnType()
Returns the return type of this method as a
Type instance. |
int |
getModifiers()
Returns the modifiers for this method.
|
String |
getName()
Returns the name of the method represented by this
Method
instance. |
Annotation[][] |
getParameterAnnotations()
Returns an array of arrays that represent the annotations of the formal
parameters of this method.
|
Class<?>[] |
getParameterTypes()
Returns an array of
Class objects associated with the parameter
types of this method. |
Class<?> |
getReturnType()
Returns the
Class associated with the return type of this
method. |
TypeVariable<Method>[] |
getTypeParameters()
Returns the declared type parameters in declaration order.
|
int |
hashCode()
Returns an integer hash code for this object.
|
Object |
invoke(Object receiver,
Object... args)
Returns the result of dynamically invoking this method.
|
boolean |
isAnnotationPresent(Class<? extends Annotation> annotationType)
Indicates whether or not this element has an annotation with the
specified annotation type (including inherited annotations).
|
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 this
method.
|
compareParameters, equalMethodParameters, getAccessFlags, getDexMethodIndexisAccessible, setAccessible, setAccessiblepublic static final Comparator<Method> ORDER_BY_SIGNATURE
public Annotation[] getAnnotations()
AnnotatedElementgetAnnotations in interface AnnotatedElementgetAnnotations in class AbstractMethodpublic int getModifiers()
Modifier class should
be used to decode the result.getModifiers in interface MemberModifierpublic boolean isVarArgs()
true if a vararg is declared, false otherwisepublic boolean isBridge()
true if this method is a bridge, false otherwisepublic boolean isSynthetic()
isSynthetic in interface Membertrue if this method is synthetic, false otherwisepublic String getName()
Method
instance.getName in interface MembergetName in class AbstractMethodpublic Class<?> getDeclaringClass()
getDeclaringClass in interface Memberpublic Class<?>[] getExceptionTypes()
Class instances. If
this method has no declared exceptions, an empty array is returned.public Class<?>[] getParameterTypes()
Class objects associated with the parameter
types of this method. If the method was declared with no parameters, an
empty array will be returned.public Class<?> getReturnType()
Class associated with the return type of this
method.public int hashCode()
Object.equals(java.lang.Object) returns true must return
the same hash code value. This means that subclasses of Object
usually override both methods or neither method.
Note that hash values must not change over time unless information used in equals comparisons also changes.
See Writing a correct
hashCode method
if you intend implementing your own hashCode method.
Equivalent to getDeclaringClass().getName().hashCode() ^ getName().hashCode().
hashCode in class ObjectObject.equals(java.lang.Object)public boolean equals(Object other)
other has the same declaring class, name,
parameters and return type as this method.equals in class AbstractMethodother - the object to compare this instance with.true if the specified object is equal to this Object; false otherwise.Object.hashCode()public String toGenericString()
public TypeVariable<Method>[] getTypeParameters()
GenericDeclarationgetTypeParameters in interface GenericDeclarationpublic Type[] getGenericParameterTypes()
Type instances, in
declaration order. If this method has no parameters, an empty array is
returned.GenericSignatureFormatError - if the generic method signature is invalidTypeNotPresentException - if any parameter type points to a missing typeMalformedParameterizedTypeException - if any parameter type points to a type that cannot be
instantiated for some reasonpublic boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
AnnotatedElementisAnnotationPresent in interface AnnotatedElementisAnnotationPresent in class AbstractMethodannotationType - the type of the annotation to search fortrue if the annotation exists, false otherwisepublic Type[] getGenericExceptionTypes()
Type instances. If
this method has no declared exceptions, an empty array will be returned.GenericSignatureFormatError - if the generic method signature is invalidTypeNotPresentException - if any exception type points to a missing typeMalformedParameterizedTypeException - if any exception type points to a type that cannot be
instantiated for some reasonpublic Type getGenericReturnType()
Type instance.GenericSignatureFormatError - if the generic method signature is invalidTypeNotPresentException - if the return type points to a missing typeMalformedParameterizedTypeException - if the return type points to a type that cannot be
instantiated for some reasonpublic Annotation[] getDeclaredAnnotations()
AnnotatedElementgetDeclaredAnnotations in interface AnnotatedElementgetDeclaredAnnotations in class AbstractMethodpublic <A extends Annotation> A getAnnotation(Class<A> annotationType)
AnnotatedElementnull if no annotation with the specified type is present
(including inherited annotations).getAnnotation in interface AnnotatedElementgetAnnotation in class AbstractMethodannotationType - the type of the annotation to search fornullpublic Annotation[][] getParameterAnnotations()
getParameterAnnotations in class AbstractMethodAnnotation instancespublic Object getDefaultValue()
null if noneTypeNotPresentException - if this annotation member is of type Class and no
definition can be foundpublic Object invoke(Object receiver, Object... args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException
receiver.methodName(arg1, arg2, ... , argN).
If the method is static, the receiver argument is ignored (and may be null).
If the method takes no arguments, you can pass (Object[]) null instead of
allocating an empty array.
If you're calling a varargs method, you need to pass an Object[] for the
varargs parameter: that conversion is usually done in javac, not the VM, and
the reflection machinery does not do this for you. (It couldn't, because it would be
ambiguous.)
Reflective method invocation follows the usual process for method lookup.
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 itself is returned. If the method is declared to return a primitive type, the return value is boxed. If the return type is void, null is returned.
receiver - the object on which to call this method (or null for static methods)args - the arguments to the methodNullPointerException - if receiver == null for a non-static methodIllegalAccessException - if this method is not accessible (see AccessibleObject)IllegalArgumentException - if the number of arguments doesn't match the number of parameters, the receiver
is incompatible with the declaring class, or an argument could not be unboxed
or converted by a widening conversion to the corresponding parameter typeInvocationTargetException - if an exception was thrown by the invoked methodpublic String toString()
public native Object
java.lang.Method.invoke(Object,Object) throws
IllegalAccessException,IllegalArgumentException
,InvocationTargetException