79488153

Date: 2025-03-06 03:08:53
Score: 0.5
Natty:
Report link

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.
Reasons:
  • Blacklisted phrase (1): ???
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: alalalala