The fundamental problem is that there is no inheritance relationship between List<ChildA>
and List<Parent>
. You mistakenly believe that ChildA
inherits from Parent
, so List<ChildA>
inherits from List<Parent>
. This is wrong.
List<ChildA>
inherits from List<? extends Parent>
.
If you understand list as "house", maybe you can figure this problem out:
public interface Parent { }
public interface Boys extends Parent{ }
public interface Girls extends Parent{ }
List<? extends Parent> aHouseForChildrenWhoExtendsParent = new List<Boys>(); // boys house.
List<? extends Parent> otherHouseForChildrenWhoExtendsParent = new List<Grils>(); // grils house.
List<Parent> parentHouse = new List<Boys>(); // ??? this is parent house, boys and girls can not go in here.