小编txt*_*low的帖子

带有通配符类型参数的map上的flatMap

我想写这样的东西:

trait Typed[T]

trait Test {

  def testMap: Map[Typed[_], Int]

  def test = testMap.flatMap {case (typed, size) => Seq.fill(size)(typed)}
}
Run Code Online (Sandbox Code Playgroud)

但是我收到以下错误:

error: no type parameters for method flatMap: (f: ((Typed[_], Int)) => Traversable[B])(implicit bf: scala.collection.generic.CanBuildFrom[scala.collection.immutable.Map[com.quarta.service.querybuilder.Typed[_],Int],B,That])That exist so that it can be applied to arguments (((Typed[_], Int)) => Seq[Typed[_0]] forSome { type _0 })
--- because ---
argument expression's type is not compatible with formal parameter type;
found   : ((Typed[_], Int)) => Seq[Typed[_0]] forSome { type _0 }
required: ((Typed[_], Int)) …
Run Code Online (Sandbox Code Playgroud)

generics types scala scala-collections

4
推荐指数
1
解决办法
1549
查看次数

标签 统计

generics ×1

scala ×1

scala-collections ×1

types ×1