Java Reference
In-Depth Information
is always true (assuming
i
is a valid index of course).
Type variable objects are created on demand by the reflection methods
that return them, and there is no requirement that you receive the
same
TypeVariable
object each time you ask for the same type variable.
However, the objects returned for a given type variable must be equi-
valent according to the
equals
method. The bounds for a type variable
are not created until
getBounds
is invoked, so
getBounds
can throw
TypeNotPresentException
if a type used in the bounds cannot be found. It
can also throw
MalformedParameterizedTypeException
if any of the bounds
refers to a
ParameterizedType
instance that cannot be created for some
reason.
16.9.2. Parameterized Types
Parameterized types, such as
List<String>
, are represented by objects
that implement the
ParameterizedType
interface. You can obtain the ac-
tual type arguments for the parameterized type from
getActualTypeAr-
guments
, which returns an array of
Type
objects. For example,
getActu-
alTypeArguments
invoked on the parameterized type
List<String>
would
yield an array of length one, containing
String.class
as its only element.
The
getOwnerType
method (which perhaps would have been better called
geTDeclaringType
) returns the
Type
object for the type in which this
Para-
meterizedType
object is a member. If this is not a member of another type
then
null
is returned. This is analogous to the
Class.getDeclaringClass
method except that a
Type
object is returned.
Like
TypeVariable
objects,
ParameterizedType
objects are created on de-
mand and are not always the same object, so you should use
equals
not
==
to check for equivalent parameterized type objects. Also, when a
parameterized type is created, all its type arguments are also created,
and this applies recursively. Both of the above methods will sometimes
throw either
TypeNotFoundException
or
MalformedParameterizedTypeExcep-
tion
.