Java Reference
In-Depth Information
Finally, ParameterizedType also has the method getrawType , which returns
the Class object for the raw type of the parameterized type. For ex-
ample, if getrawType were invoked on the parameterized type
List<String> it would return List.class . Even though a raw type is by
definition a non-generic class or interface, getrawType returns a Type in-
stance rather than a Class<?> , so a cast must be applied, as you saw in
the TypeDesc program.
16.9.3. Wildcards
A wildcard type parameter is represented by an instance that imple-
ments the WildcardType interface. For example, given a parameterized
type for List<?extends Number> , getActualTypeArguments will give an array of
length one containing a WildcardType object representing " ?extends Num-
ber ".
WildcardType has two methods: getUpperBounds and getLowerBounds , which
return Type arrays representing the upper and lower bounds of the wild-
card, respectively. If no upper bound was specified, the upper bound
is Object . If a wildcard has no lower bound, getLowerBounds returns an
empty array.
As with TypeVariable , the type objects for bounds are created on de-
mand, so TypeNotPresentException or MalformedParameterizedTypeException
may be thrown.
16.9.4. Generic Arrays
The last of the type related interfaces is GenericArrayType . This repres-
ents array types in which the component type is a parameterized type
or a type variable. [4] GenericArrayType has a single method, getGener-
icComponentType , which returns the Type for the component type of the
array, which will be either a ParameterizedType or a TypeVariable . For ex-
ample, for a List<String>[] field, getGenericType would return a GenericAr-
 
Search WWH ::




Custom Search