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

斯卡拉:什么是特质TraversableOnce? TraversableOnce和Travers

发布时间:2020-12-16 18:45:42 所属栏目:安全 来源:网络整理
导读:TraversableOnce:“集合的模板特征,可以遍历一次或一次或多次.” 我不明白这句话.为什么可以遍历更多次?不仅一次吗? 谢谢! 解决方法 Scaladoc也说 This trait exists primarily to eliminate code duplication between Iterator and Traversable,and thu
TraversableOnce:“集合的模板特征,可以遍历一次或一次或多次.”

我不明白这句话.为什么可以遍历更多次?不仅一次吗?
谢谢!

解决方法

Scaladoc也说

This trait exists primarily to eliminate code duplication between Iterator and Traversable,and thus implements some of the common methods that can be implemented solely in terms of foreach without access to a Builder.

迭代器只能被“遍历”一次.可以遍历Traversable多次.

从本质上讲,TraversableOnce是一个接口,它抽象出你如何处理Iterators和Traversables.您的代码可以接收Iterator或Traversable,并以完全相同的方式处理它们!

为了很好地解释Collections库中使用的许多特性,我相信the Scala 2.8 Collections Design Tutorial的大多数(如果不是全部)仍然是正确的.

(编辑:李大同)

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

    推荐文章
      热点阅读