Based on @drexin's answer using ad-hoc polymorphism, I just slightly modified the use of the question's signature to make it clearer.
def dump[T](a: A[T], t: T) = C.dump(a, t)
case class A[T](t: T)
trait Dumper[T] {
def dump(a: A[T], t: T): Unit
}
class B {
def dump[T](a: A[T], t: T)(implicit dumper: Dumper[T]) = dumper.dump(a, t)
}
implicit val IntDummper = new Dumper[Int] {
override def dump(a: A[Int], t: Int): Unit = {
println("int dummper processing it")
}
}
implicit val StringDummper = new Dumper[String] {
override def dump(a: A[String], t: String): Unit = {
println("string dummper processing it")
}
}
val result = new B
result.dump(A("3"), "3") //string dummper processing it
result.dump(A(3), 3) //int dummper processing it
source
share