So it seems that if you define a method thusly (note: requires Java 5 ("Gangly Geek") or
public void doSomethingGenerically(Collection<Supertype>){...}and you attempt to call it thusly:
List<SubtypeOfSupertype> bogus = new ArrayList<SubtypeOfSupertype>();you get a compiler error saying you can't call that method with those arguments.
doSomethingGenerically(bogus);
So my question here is: why the heck not?
Inheritance 101: a
List
isa Collection
, right? A SubtypeOfSupertype
isa Supertype
, right? So why am I being told that an instance of type List<SubtypeOfSupertype>
isn'ta Collection<Supertype>
?Paging Dr. Liskov...