How to pattern match on generic type in Scala?
Maybe this will help def matchContainer[A: Manifest](c: Container[A]) = c match { case c: Container[String] if manifest <:< manifest[String] => println(c.value.toUpperCase) case c: Container[Double] if manifest <:< manifest[Double] => println(math.sqrt(c.value)) case c: Container[_] => println(“other”) } Edit: As Impredicative pointed out, Manifest is deprecated. Instead you could do the following: import reflect.runtime.universe._ def matchContainer[A: TypeTag](c: … Read more