加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Scala的MapLike,ListLike,SeqLike等每个与Map,List,Seq等进行比

发布时间:2020-12-16 09:31:18 所属栏目:安全 来源:网络整理
导读:有人可以帮助我了解Scala在收集API中的各种“Like”特征。我一直在阅读,试图比较每一个没有运气。我想我可以看到Map为例,扩展了MapLike – 添加了2个具体的方法。但是,这就提出了为什么要这样做的问题呢?为什么在Collections API中不仅仅具有1个Map trai
有人可以帮助我了解Scala在收集API中的各种“Like”特征。我一直在阅读,试图比较每一个没有运气。我想我可以看到Map为例,扩展了MapLike – 添加了2个具体的方法。但是,这就提出了为什么要这样做的问题呢?为什么在Collections API中不仅仅具有1个Map trait,而不是Map和MapLike?

谢谢!

解决方法

这些细节的最佳来源是 Martin Odersky and Lex Spoon’s “What’s New in Scala 2.8: The Architecture of Scala Collections”:

The Scala collection library avoids code duplication and achieves the
“same-result-type” principle by using generic builders and traversals
over collections in so-called implementation traits. These traits
are named with a Like suffix; for instance,IndexedSeqLike is the
implementation trait for IndexedSeq,and similarly,
TraversableLike is the implementation trait for Traversable.
Collection classes such as Traversable or IndexedSeq inherit all
their concrete method implementations from these traits.
Implementation traits have two type parameters instead of one for
normal collections. They parameterize not only over the collection’s
element type,but also over the collection’s representation type,
i.e.,the type of the underlying collection,such as Seq[I] or List[T]

如果您想将自己的集合类与Collections API集成在一起,或者您只想更深入地了解库的工作原理,那么整篇文章就非常有用。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读