I am trying to undertand how captured conversion works for wildcard types. There is a section in JLS explaining that:
Let
G
name a generic type declaration (§8.1.2, §9.1.2) withn
type parametersA1,...,An
with corresponding boundsU1,...,Un
.There exists a capture conversion from a parameterized type
G<T1,...,Tn>
(§4.5) to a parameterized typeG<S1,...,Sn>
, where, for1 ≤ i ≤ n
:
If
Ti
is a wildcard type argument (§4.5.1) of the form?
, thenSi
is a fresh type variable whose upper bound isUi[A1:=S1,...,An:=Sn]
and whose lower bound is thenull
type (§4.1).If
Ti
is a wildcard type argument of the form? extends Bi
, thenSi
is a fresh type variable whose upper bound isglb(Bi, Ui[A1:=S1,...,An:=Sn])
and whose lower bound is thenull
type.
glb(V1,...,Vm)
is defined asV1 & ... & Vm
.It is a compile-time error if, for any two classes (not interfaces)
Vi
andVj
,Vi
is not a subclass ofVj
or vice versa.If
Ti
is a wildcard type argument of the form? super Bi
, thenSi
is a fresh type variable whose upper bound isUi[A1:=S1,...,An:=Sn]
and whose lower bound isBi
.Otherwise,
Si = Ti
.
The thing that is not clear to me is Ui[A1:=S1,...,An:=Sn]
. What does it mean? I could not find a definition for that searching through the JLS.
{}`, the bound of S (`U_1`) is `Number` but once replaced by type arguments, e.g. `Test t` the `U_1` becomes `Integer` since we can't substitute the first parameter by `Number` anymore because `S` depends on the bound of `T`. Hence, we have to look at `U_1 [A1:=S1,...,An:=Sn]` and not just simply `U_1` – Turkhan Badalov Apr 22 '23 at 09:12