Implement Ordered trait with covariant generic

Viewed 272

Is there a way mix in the Ordered trait for a covariant generic?

I have the following code:

trait Foo[+T  <: Foo[T]] extends Ordered[T] {

  def id: Int

  override def compare(that : T) : Int = {
    this.id compare that.id
  }    
}

Where I need T covariant and would like ordered to work too. The version above gives the "covariant type in contravariant position error".

2 Answers
Related