【发布时间】:2011-06-04 22:42:21
【问题描述】:
添加两个Set[Int] 作品:
Welcome to Scala version 2.8.1.final (Java HotSpot(TM) Server VM, Java 1.6.0_23).
Type in expressions to have them evaluated.
Type :help for more information.
scala> Set(1,2,3) ++ Set(4,5,6)
res0: scala.collection.immutable.Set[Int] = Set(4, 5, 6, 1, 2, 3)
但添加两个Set[Any] 不会:
scala> Set[Any](1,2,3) ++ Set[Any](4,5,6)
<console>:6: error: ambiguous reference to overloaded definition,
both method ++ in trait Addable of type (xs: scala.collection.TraversableOnce[Any])scala.collection.immutable.Set[Any]
and method ++ in trait TraversableLike of type [B >: Any,That](that: scala.collection.TraversableOnce[B])(implicit bf: scala.collection.generic.CanBuildFrom[scala.collection.immutable.Set[Any],B,That])That
match argument types (scala.collection.immutable.Set[Any])
Set[Any](1,2,3) ++ Set[Any](4,5,6)
^
有解决此错误的建议吗?
【问题讨论】:
-
已在 scala2.9 中修复。 Addable 已被删除。请参阅 [ticket4059][lampsvn.epfl.ch/trac/scala/ticket/4059] 了解更多信息。
标签: scala scala-2.8 scala-collections