I have a trait that requires a function with a ClassTag
trait Foo[T] {
def bar(a: List[T])(implicit ev: ClassTag[T]): Unit
}
Now I have a class that needs to extend that trait, but it also has uses for its ClassTag for other methods, e.g.
class MyClass[T](implicit classTag: ClassTag[T]) extends Foo[T] {
override def bar(a: List[T])(implicit ev: ClassTag[T]): Unit = { /* do stuff */ }
def other(p: Map[String, T]) = /* other stuff where I need the ClassTag */
}
When this is compiled I get an error message along the lines of:
Error:scalac: ambiguous implicit values:
both value classTag in class MyClass of type scala.reflect.ClassTag[T]
and value ev of type scala.reflect.ClassTag[T]
match expected type scala.reflect.ClassTag[T]
Is there a way I can accommodate both the class level ClassTag and override the method from the parent trait?
You can simply give the same name to both of them.