« Return to Thread: parametric types and variance

parametric types and variance

by Christoph Driessen :: Rate this Message:

Reply to Author | View in Thread

Hi all,

can anyone explain to me why the following code compiles? As I  
understand it, Aa acts as the lower bound in the implementation of  
classify in class AaClassifier and so I wonder why I'm able to pass in  
a String.

Cheers
Christoph


object Test {
     def main(args: Array[String]) {
         println(new AaClassifier().classify("a"))
     }
}

trait Classifier[+T] {
     def classify[U >: T](t: U): String
}

class AaClassifier extends Classifier[Aa] {
     def classify[T >: Aa](t: T) = t.toString
}

class Aa

 « Return to Thread: parametric types and variance