If I understand your question correctly, the answer is as follows: you can do this if Typed covariant in T , that is, trait Typed[+T] .
Example
scala> :paste // Entering paste mode (ctrl-D to finish) class Typed[+T: Manifest] { override def toString = "Typed[" + implicitly[Manifest[T]].toString + "]" } trait Test { def testMap: Map[Typed[_], Int] def foo = testMap flatMap { case (t, s) => Seq.fill(s)(t) } } val bar = new Test { def testMap = Map(new Typed[Double]() -> 3, new Typed[Int]() -> 5) } // Hit Ctrl-D scala> bar.foo res0: scala.collection.immutable.Iterable[Seq[Typed[Any]]] = List(Typed[Double], Typed[Double], Typed[Double], Typed[Int], Typed[Int], Typed[Int], Typed[Int], Typed[Int])
Note that I made the Typed class in this example to get a better result. You can, of course, stick with trait .
Now, why is covariance necessary?
Covariance basically means that if A <: B , then X[A] <: X[B] . Therefore, if you declared testMap as Map[Typed[Any], Int] , and Typed were invariant, you were not allowed to pass, for example. a Typed[Double] for a Typed[Any] , although Double <: Any . Here the scala compiler seems to replace _ with Any in the covariant case (see extempore's comment for development on this).
To explain the underscore problem, I would name Luigi's answer.
source share