我已经定义了一个具有上限类型的类型参数的类,并且已经为该上限类型定义了一个排序。我如何得到"实例/值"类型T,U所以我可以在isGreaterAnimal方法中使用它们吗?
class Animal[T <: Reflect] {
implicit val ord = new Ordering[Reflect] {
def compare(x: Reflect, y: Reflect): Int = if(x.canReflect && !y.canReflect) 1 else if(!x.canReflect && y.canReflect) -1 else 0
}
def isGreaterAnimal(that: Animal[T]) = ord.gt(?,?) // ????
}
trait Reflect{
val canReflect: Boolean
}
trait Reflective extends Reflect{
val canReflect = true
}
trait Automaton extends Reflect{
val canReflect = false
}
val reflective = new Animal[Reflective]
val robot = new Animal[Automaton]
reflective.isGreaterAnimal(robot) // should return true