Generics and polymorphism
Hi everybody,
Could anybody give me some info (maybe some good links about generics)
why I can't do something like this:
class Parent{}
class Childextends Parent{}
List<Parent> myList =new ArrayList<Child>();
Hi everybody,
Could anybody give me some info (maybe some good links about generics)
why I can't do something like this:
class Parent{}
class Childextends Parent{}
List<Parent> myList =new ArrayList<Child>();
class Child2 extends Parent {}
You can add a Child2 object to a List < Parent> but not to a (Array)List < Child >.
Covariant/Contravariant functorality issues and all that.