I understand why I can't cast one class that generelized with A, to same class that generelized with B (if B extends A). It's explained here. But I have no clue why this code doesn't work.
public class A {
public static void main(String[] args) {
D<? extends B> d = new D<>();
d.foo(new B()); // compilation error
d.foo(new C()); // compilation error
}
}
class B {
}
class C extends B {
}
class D<T> {
void foo(T t) {
}
}
I would like to have the reference to official docs where this principle is explained.