How do I get an instance of the type class associated with a context bound?

Using the implicitly method The most common and general approach is to use the implicitly method, defined in Predef: def add[T: Numeric](x: T, y: T) = implicitly[Numeric[T]].plus(x,y) Obviously, this is somewhat verbose and requires repeating the name of the type class. Referencing the evidence parameter (don’t!) Another alternative is to use the name of the … Read more

How to get ClassTag form TypeTag, or both at same time?

The library doesn’t provide a built-in method that directly converts a TypeTag to a ClassTag, but you can write one: import reflect.runtime.universe._ import reflect.ClassTag def typeToClassTag[T: TypeTag]: ClassTag[T] = { ClassTag[T]( typeTag[T].mirror.runtimeClass( typeTag[T].tpe ) ) } Then in your method just add before the implicit ClassTag is needed: implicit val c = typeToClassTag[T]