class Super {override def toString = "Super"}
class Sub extends Super {override def toString = "Sub"; def subMethod {} }
val sup = new Super
val sub = new Sub
Imagine the following:
class Foo[+T] {
def bar(x: T) = println(x)
}
Foo T, ( upcast, a Foo[Sub] Foo[Super]):
val foo : Foo[Super] = new Foo[Sub] {
override def bar(x: Sub) = x.subMethod
}
Foo, , Foo[Super], , bar , bar Sub:
foo.bar(sup)