Java Reference
In-Depth Information
16.7. The
Method
Class
The
Method
class, together with its inherited
Member
methods allows you to
obtain complete information about the declaration of a method:
public Type
getGenericReturnType()
Returns the
Type
object for the type returned by this method. If
the method is declared
void
the returned object is
void.class
.
public Type[]
getGenericParameterTypes()
Returns an array of
Type
objects with the type of each para-
meter of this method, in the order in which the parameters are
declared. If the method has no parameters an empty array is
returned.
public Type[]
getGenericExceptionTypes()
Returns an array of
Type
objects for each of the exception types
listed in the
throws
clause for this method, in the order they are
declared. If there are no declared exceptions an empty array
is returned.
There are also the legacy methods
geTReturnType
,
getParameterTypes
, and
getExceptionTypes
that return
Class
objects instead of
Type
objects. As with
Field.getType
, parameterized types and type variables are represented by
the
Class
objects of their erasures.
Method
implements
AnnotatedElement
, and the annotations on a method can
be queried as discussed in
Section 16.2
on page
414
. Additionally,
Meth-
od
provides the
getParameterAnnotations
method to provide access to the
annotations applied to the method's parameters. The
getParameterAnnota-
tions
method return an array of
Annotation
arrays, with each element of
the outermost array corresponding to the parameters of the method, in
the order they are declared. If a parameter has no annotations then a