I have a derived class Father
and a base class Parent
e.g.
public static class Parent {
}
public static class Father extends Parent {
}
I wonder why the followings are not allowed?
public static List<Parent> foo() {
List<? extends Parent> list = new ArrayList<>();
list.add(new Parent()); // 1. why is this not allowed?
list.add(new Father()); // 2. why is this not allowed?
return list; // 3. why is this not allowed?
}