Computer Science Canada [Scala] Generics tip du jour |
Author: | wtd [ Tue Oct 16, 2007 1:38 am ] | ||||||||||||||||
Post subject: | [Scala] Generics tip du jour | ||||||||||||||||
So you create a generic class Foo.
Now, you have classes A and B.
Now, we can do something very simple.
It works fine. Now, let's extend Foo.
And now the following works fine too.
But... what about...
This fails! But, why should it? B is a subtype of A, so Foo[B] should be a subtype of Foo[A], right? We can make it work.
Now we can even...
|