升级到Scala 2.12之后,我遇到了一个奇怪的编译问题:
val c = Map("a" -> Set[Map[String, String]](), "b" -> Map[String, String]())
抛出这个例外:
Error:(19, 7) type arguments [?,Iterable[Equals] with String with scala.collection.immutable.Map[String,String] => Any with scala.collection.generic.Subtractable[_ >: String with scala.collection.immutable.Map[String,String] <: Object, Iterable[Equals] with String with scala.collection.immutable.Map[String,String] => Any with scala.collection.generic.Subtractable[_ >: String with scala.collection.immutable.Map[String,String] <: Object, Iterable[Equals] with String with scala.collection.immutable.Map[String,String] => Any with scala.collection.generic.Subtractable[_ >: String with scala.collection.immutable.Map[String,String] <: Object, Equals]]{def seq: Iterable[Equals] with String with scala.collection.immutable.Map[String,String] => Any with scala.collection.generic.Subtractable[_ >: String with scala.collection.immutable.Map[String,String] <: Object, Equals]}]{def seq: Iterable[Equals] with String with scala.collection.immutable.Map[String,String] => Any with scala.collection.generic.Subtractable[_ >: String with scala.collection.immutable.Map[String,String] <: Object, Iterable[Equals] with String with scala.collection.immutable.Map[String,String] => Any with scala.collection.generic.Subtractable[_ >: String with scala.collection.immutable.Map[String,String] <: Object, Equals]]{def seq: Iterable[Equals] with String with scala.collection.immutable.Map[String,String] => Any with scala.collection.generic.Subtractable[_ >: String with scala.collection.immutable.Map[String,String] <: Object, Equals]}}] do not conform to trait Subtractable's type parameter bounds [A,+Repr <: scala.collection.generic.Subtractable[A,Repr]]
答案 0 :(得分:2)
它看起来像一个bug。如果模拟不存在,您可以在bug tracker中发布。
作为解决方法,尝试将值附加到地图。
scala> val c = Map.empty[String,Iterable[Any]] + ("a" -> Set[Map[String, String]]()) + ("b" -> Map[S
tring, String]())
c: scala.collection.immutable.Map[String,Iterable[Any]] = Map(a -> Set(), b -> Map())