Java Reference
In-Depth Information
We have
A
=
G
<
W
>
>>
F
=
G
<
U
>
for some type expression
W
. Since
W
is a
type expression (and not a wildcard type argument), it must be the case that
W
=
U
, by the invariance of parameterized types.
Otherwise, if
A
is of the form
G
<
...,
X
k-1
,
? extends
W
,
X
k+1
, ...
>
, this algorithm
is applied recursively to the constraint
W
>>
U
.
We have
A
=
G
<? extends
W
>
>>
F
=
G
<
U
>
for some type expression
W
. It must
be the case that
W
>>
U
, by the subtyping rules for wildcard types.
Otherwise, if
A
is of the form
G
<
...,
X
k-1
,
? super
W
,
X
k+1
, ...
>
, this algorithm is
applied recursively to the constraint
W
<<
U
.
We have
A
=
G
<? super
W
>
>>
F
=
G
<
U
>
for some type expression
W
. It must
be the case that
W
<<
U
, by the subtyping rules for wildcard types.
Otherwise, no constraint is implied on
T
j
.
• If
F
has the form
G
<
...,
Y
k-1
,
? extends
U
,
Y
k+1
, ...
>
, where
U
is a type expression that
involves
T
j
, then:
♦ If
A
is an instance of a non-generic type, then no constraint is implied on
T
j
.
Once again restricting the analysis to the unary case, we have the constraint
A
>>
F
=
G
<? extends
U
>
.
A
must be a supertype of the generic type
G
. However,
since
A
is not a parameterized type, it cannot depend upon
U
in any way. It is
a supertype of the type
G
<? extends
X
>
for every
X
such that
? extends
X
is a valid
type argument to
G
. No meaningful constraint on
U
can be derived from
A
.
♦ If
A
is an invocation of a generic type declaration
H
, where
H
is either
G
or su-
perclass or superinterface of
G
, then:
If
H
≠
G
, then let
S
1
, ...,
S
n
be the type parameters of
G
, and let
H
<
U
1
, ...,
U
l
>
be the unique invocation of
H
that is a supertype of
G
<
S
1
, ...,
S
n
>
, and let
V
=
H
<? extends
U
1
, ...,
? extends
U
l
>[
S
k
=
U
]
. Then this algorithm is applied recurs-
ively to the constraint
A
>>
V
.
Our goal here is once more to simplify the relationship between
A
and
F
, and
recursively invoke the algorithm on a simpler case, where the type argument
is known to be an invocation of the same generic type as the formal.
Assume both
H
and
G
have only a single type argument. Since we have the
constraint
A
=
H
<
X
>
>>
F
=
G
<? extends
U
>
, where
H
is distinct from
G
, it must
be the case that
H
is some proper superclass or superinterface of
G
. There must
be an invocation of
H
<
Y
>
, such that
H
<
X
>
>>
H
<
Y
>
, that we can use instead of
F
=
G
<? extends
U
>
.