In scala abstract class, if you want to define a context bound, you can simply use, e.g. [T: ClassTag] in parameter, however this is not possible in trait:
trait Foo[T: ClassTag]
Error:(11, 35) traits cannot have type parameters with context bounds `: ...' nor view bounds `<% ...'
trait Foo[T: ClassTag]
^
if you define:
trait Foo[T] {
implicit def ctg: ClassTag[T] = implicitly[ClassTag[T]]
}
object Bar extends Foo[Int]
then any attempt to read ctg inside Bar will trigger a StackOverflowError, as the implicit parameter becomes tail-recursive.
So what's the best way to allow ctg to be defined in a trait that automatically expose subclasses to context bound?