Java Reference
In-Depth Information
These type variables are known as the
type parameters
of the class. The type parameter
section follows the class name and is delimited by angle brackets.
TypeParameters:
<
TypeParameterList
>
TypeParameterList:
TypeParameterList
,
TypeParameter
TypeParameter
In a class's type parameter section, a type variable
T directly depends
on a type variable
S
if
S
is the bound of
T
, while
T depends
on
S
if either
T
directly depends on
S
or
T
directly
depends on a type variable
U
that depends on
S
(using this definition recursively).
It is a compile-time error if a type variable in a class's type parameter section depends on
itself.
Example 8.1.2-1. Mutually Recursive Type Variable Bounds
interface ConvertibleTo<T> {
T convert();
}
class ReprChange<T extends ConvertibleTo<S>,
S extends ConvertibleTo<T>> {
T t;
void set(S s) { t = s.convert(); }
S get()
{ return t.convert(); }
}
sible invocation of the type parameter section by type arguments. All of these parameter-
ized types share the same class at run time.
For instance, executing the code:
Vector<String> x = new Vector<String>();
Vector<Integer> y = new Vector<Integer>();
boolean b = x.getClass() == y.getClass();
will result in the variable
b
holding the value
true
.