I am trying to undertand how captured conversion works for wildcard types. There is a section in JLS explaining that:
Let
Gname a generic type declaration (§8.1.2, §9.1.2) withntype parametersA1,...,Anwith 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
Tiis a wildcard type argument (§4.5.1) of the form?, thenSiis a fresh type variable whose upper bound isUi[A1:=S1,...,An:=Sn]and whose lower bound is thenulltype (§4.1).If
Tiis a wildcard type argument of the form? extends Bi, thenSiis a fresh type variable whose upper bound isglb(Bi, Ui[A1:=S1,...,An:=Sn])and whose lower bound is thenulltype.
glb(V1,...,Vm)is defined asV1 & ... & Vm.It is a compile-time error if, for any two classes (not interfaces)
ViandVj,Viis not a subclass ofVjor vice versa.If
Tiis a wildcard type argument of the form? super Bi, thenSiis 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