Name
Method
Synopsis
This
class represents a method. Instances of Method are
obtained by calling the getMethod( ) and related
methods of java.lang.Class.
Method implements the Member
interface, so you can use the methods of that interface to obtain the
method name, modifiers, and declaring class. In addition,
getReturnType( )
, getParameterTypes(
), and getExceptionTypes( ) also return
important information about the represented method.
Perhaps most importantly, the
invoke( ) method allows the method represented by
the Method object to be invoked with a specified
array of argument values. If any of the arguments are of primitive
types, they must be converted to their corresponding wrapper object
types in order to be passed to invoke( ). If the
represented method is an instance method (i.e., if it is not
static), the instance on which it should be
invoked must also be passed to invoke( ). The
return value of the represented method is returned by
invoke( ). If the return value is a primitive
value, it is first converted to the corresponding wrapper type. If
the invoked method causes an exception, the
Throwable object it throws is wrapped within the
InvocationTargetException that is thrown by
invoke( ).
In Java 5.0,
Method
implements
GenericDeclaration to support reflection on the
type variables defined by generic methods and
AnnotatedElement to support reflection on method
annotations. Additionally, getParameterAnnotations(
)
supports reflection on method parameter annotations. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access