1
II想了解Scala集合:创建通过添加一个新的集合如下类型集合
class NewColl[V](values:Vector[V],someOtherParams)
extends IndexedSeq[V] with IndexedSeqLike[V, NewColl[V]] {
def fromSeq[V](seq: Seq[V]): NewColl[V] = ...
override def newBuilder[V]: Builder[V, NewColl[V]] =
new ArrayBuffer[V] mapResult fromSeq[V]
}
,但我得到了以下错误:
overriding method newBuilder in trait TraversableLike of type => scala.collection.mutable.Builder[V,NewColl[V]]; method newBuilder in trait GenericTraversableTemplate of type => scala.collection.mutable.Builder[V,IndexedSeq[V]] has incompatible type
任何想法?
“map”的结果仍然是IndexedSeq而不是NewColl! – teucer
@teucer,你需要提供一个'CanBuildFrom',参见http://www.scala-lang.org/docu/files/collections-api/collections-impl_5.html。我建议浏览/阅读* Scala Collections的架构*,然后尝试实现您的收藏。相反,无缘无故更具挑战性。 – huynhjl