No, there is no simpler way. Manifest
has been replaced by ClassTag
and TypeTag
, but there isn't any easy way to get the needed ClassTag
- traits can't take parameters, and equals
in Any
wasn't declared to take an implicit ClassTag
, so we have to force the implementing class to provide it:
import scala.reflect.ClassTag
trait Comparable[A] extends Ordered[A] {
implicit def ct: ClassTag[A]
override def equals(that: Any) =
that match {
case that: A => compare(that) == 0
case _ => false
}
}
isInstanceOf
won't help either, it will still require the ClassTag
.