java.lang.Object | ||
↳ | java.lang.reflect.AccessibleObject | |
↳ | java.lang.reflect.Method |
This class represents a method. Information about the method can be accessed, and the method can be invoked dynamically.
[Expand]
Inherited Constants
|
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From interface
java.lang.reflect.Member
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
Indicates whether or not the specified
object
is equal to this
method.
|
||||||||||
|
Returns, for this element, the annotation with the specified type, or
null
if no annotation with the specified type is present
(including inherited annotations).
|
||||||||||
|
Returns, for this element, all annotations that are explicitly declared
(not inherited).
|
||||||||||
|
Returns the class that declares this method.
|
||||||||||
|
Returns the default value for the annotation member represented by this
method.
|
||||||||||
|
Returns the exception types as an array of
Class
instances.
|
||||||||||
|
Returns the exception types as an array of
Type
instances.
|
||||||||||
|
Returns the parameter types as an array of
Type
instances, in
declaration order.
|
||||||||||
|
Returns the return type of this method as a
Type
instance.
|
||||||||||
|
Returns the modifiers for this method.
|
||||||||||
|
Returns the name of the method represented by this
Method
instance.
|
||||||||||
|
Returns an array of arrays that represent the annotations of the formal
parameters of this method.
|
||||||||||
|
Returns an array of
Class
objects associated with the parameter
types of this method.
|
||||||||||
|
Returns the
Class
associated with the return type of this
method.
|
||||||||||
|
Returns the declared type parameters in declaration order.
|
||||||||||
|
Returns an integer hash code for this method.
|
||||||||||
|
Returns the result of dynamically invoking this method.
|
||||||||||
|
Indicates whether or not this element has an annotation with the
specified annotation type (including inherited annotations).
|
||||||||||
|
Indicates whether or not this method is a bridge.
|
||||||||||
|
Indicates whether or not this method is synthetic.
|
||||||||||
|
Indicates whether or not this method takes a variable number argument.
|
||||||||||
|
Returns the string representation of the method's declaration, including
the type parameters.
|
||||||||||
|
Returns a string containing a concise, human-readable description of this
method.
|
[Expand]
Inherited Methods
|
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.reflect.AccessibleObject
|
|||||||||||
From class
java.lang.Object
|
|||||||||||
From interface
java.lang.reflect.AnnotatedElement
|
|||||||||||
From interface
java.lang.reflect.GenericDeclaration
|
|||||||||||
From interface
java.lang.reflect.Member
|
Indicates whether or not the specified
object
is equal to this
method. To be equal, the specified object must be an instance
of
Method
with the same declaring class and parameter types
as this method.
object | the object to compare |
---|
true
if the specified object is equal to this
method,
false
otherwise
Returns, for this element, the annotation with the specified type, or
null
if no annotation with the specified type is present
(including inherited annotations).
annotationType | the type of the annotation to search for |
---|
null
Returns, for this element, all annotations that are explicitly declared (not inherited). If there are no declared annotations present, this method returns a zero length array.
Returns the class that declares this method.
Returns the default value for the annotation member represented by this method.
null
if none
TypeNotPresentException |
if this annotation member is of type
Class
and no
definition can be found
|
---|
Returns the exception types as an array of
Class
instances. If
this method has no declared exceptions, an empty array is returned.
Returns the exception types as an array of
Type
instances. If
this method has no declared exceptions, an empty array will be returned.
GenericSignatureFormatError | if the generic method signature is invalid |
---|---|
TypeNotPresentException | if any exception type points to a missing type |
MalformedParameterizedTypeException | if any exception type points to a type that cannot be instantiated for some reason |
Returns the parameter types as an array of
Type
instances, in
declaration order. If this method has no parameters, an empty array is
returned.
GenericSignatureFormatError | if the generic method signature is invalid |
---|---|
TypeNotPresentException | if any parameter type points to a missing type |
MalformedParameterizedTypeException | if any parameter type points to a type that cannot be instantiated for some reason |
Returns the return type of this method as a
Type
instance.
GenericSignatureFormatError | if the generic method signature is invalid |
---|---|
TypeNotPresentException | if the return type points to a missing type |
MalformedParameterizedTypeException | if the return type points to a type that cannot be instantiated for some reason |
Returns the name of the method represented by this
Method
instance.
Returns 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.
Annotation
instances
Returns an array of
Class
objects associated with the parameter
types of this method. If the method was declared with no parameters, an
empty array will be returned.
Returns the
Class
associated with the return type of this
method.
Returns the declared type parameters in declaration order. If there are no type parameters, this method returns a zero length array.
Returns an integer hash code for this method. Objects which are equal return the same value for this method. The hash code for this Method is the hash code of the name of this method.
Returns the result of dynamically invoking this method. Equivalent to
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 method |
NullPointerException |
if
receiver == null
for a non-static method
|
---|---|
IllegalAccessException |
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 type |
InvocationTargetException | if an exception was thrown by the invoked method |
Indicates whether or not this element has an annotation with the specified annotation type (including inherited annotations).
annotationType | the type of the annotation to search for |
---|
true
if the annotation exists,
false
otherwise
Indicates whether or not this method is a bridge.
true
if this method is a bridge,
false
otherwise
Indicates whether or not this method is synthetic.
true
if this method is synthetic,
false
otherwise
Indicates whether or not this method takes a variable number argument.
true
if a vararg is declared,
false
otherwise
Returns the string representation of the method's declaration, including the type parameters.
Returns a string containing a concise, human-readable description of this method. The format of the string is:
public native Object
java.lang.Method.invoke(Object,Object) throws
IllegalAccessException,IllegalArgumentException
,InvocationTargetException