It's the following:
A parameterized bean type is considered assignable to a parameterized required type if they have identical raw type and for each parameter:
-
the required type parameter is an actual type, the bean type parameter is a type variable and
the actual type is assignable to the upper bound, if any, of the type variable, or
We start with:
A parameterized bean type is considered assignable to a parameterized required type if they have identical raw type
So here we have:
-
required type = MyService<ClassA, ClassB>
-
bean type = MyService<T extends MasterDbo<D>,D extends DetailDbo>
both of them are parameterized and have identical raw type. So far so good. Next we need to consider parameters. Let's start with the first one. Our parameters match the following option:
the required type parameter is an actual type, the bean type parameter is a type variable and the actual type is assignable to the upper bound, if any, of the type variable, or
-
required type parameter = ClassA
-
bean type parameter = T extends MasterDbo<D>
the required type parameter is an actual type the bean type parameter is a type variable the actual type is assignable to the upper bound, if any, of the type variable
Now we need to figure out whether ClassA is assignable to MasterDbo<D> or in other words whether ClassA is a subtype of MasterDbo<D>. Per definition it is true that ClassA is a subtype of MasterDbo<ClassB> so the question is whether MasterDbo<ClassB> is assignable to MasterDbo<D extends DetailDbo>.
Per JLS D extends DetailDbo is a direct subtype of DetailDbo. Since per JLS parameterized types are invariant, MasterDbo<ClassB> is not a subtype of MasterDbo<D extends DetailDbo> and therefore not assignable to it.
|