Java Reference
In-Depth Information
If
C
had been declared in a different package than
T
, then the call to
mCDefault
would
give rise to a compile-time error, as that member would not be accessible at the point
where
T
is declared.
4.5. Parameterized Types
A
1
,...,
A
n
which have corresponding bounds
B
1
,...,
B
n
defines a set of parameterized types,
one for each possible invocation of the type parameter section.
Each parameterized type in the set is of the form
C
<
T
1
,...,
T
n
>
where each type argument
T
i
ranges over all types that are subtypes of all types listed in the corresponding bound. That
is, for each bound type
S
i
in
B
i
,
T
i
is a subtype of
S
i
[
F
1
:=
T
1
,...,
F
n
:=
T
n
]
.
A parameterized type is written as a
ClassType
or
InterfaceType
that contains at least one
type declaration specifier immediately followed by a type argument list
<
T
1
,...,
T
n
>
. The
type argument list denotes a particular invocation of the type parameters of the generic type
indicated by the type declaration specifier.
Given a type declaration specifier immediately followed by a type argument list, let
C
be
the final
Identifier
in the specifier.
It is a compile-time error if
C
is not the name of a generic class or interface, or if the number
of type arguments in the type argument list differs from the number of type parameters of
C
.
Let
P
=
C
<
T
1
,...,
T
n
>
be a parameterized type. It must be the case that, after
P
is subjected
to capture conversion (§
5.1.10
) resulting in the type
C
<
X
1
,...,
X
n
>
, for each type argument
X
i
(1 ≤
i
≤
n
),
X
i
<:
B
i
[
A
1
:=
X
1
,...,
A
n
:=
X
n
]
(§
4.10
), or a compile-time error occurs.
The notation
[
A
i
:=
T
i
]
denotes substitution of the type variable
A
i
with the type
T
i
for 1 ≤
i
≤
n
, and is used throughout this specification.
In this specification, whenever we speak of a class or interface type, we include the generic
version as well, unless explicitly excluded.
Examples of parameterized types:
•
Vector<String>
•
Seq<Seq<A>>
•
Seq<String>.Zipper<Integer>
•
Collection<Integer>