首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >集合扩展了Iterable,但为什么集合声明Iterable函数(与Iterable相同)

集合扩展了Iterable,但为什么集合声明Iterable函数(与Iterable相同)
EN

Stack Overflow用户
提问于 2019-06-26 11:00:27
回答 1查看 72关注 0票数 0

我的java版本是"1.8.0_192“

代码语言:javascript
复制
/**
 * Returns an iterator over the elements in this collection.  There are no
 * guarantees concerning the order in which the elements are returned
 * (unless this collection is an instance of some class that provides a
 * guarantee).
 *
 * @return an <tt>Iterator</tt> over the elements in this collection
 */
Iterator<E> iterator();

这是集合接口。

代码语言:javascript
复制
/**
 * Returns an iterator over elements of type {@code T}.
 *
 * @return an Iterator.
 */
Iterator<T> iterator();

这是Iterable接口。

EN

回答 1

Stack Overflow用户

发布于 2019-06-26 11:09:42

真的没有理由两者兼而有之。如果你看一下Collectionsince部分,你会发现它是在1.2中添加的,而Iterable是在1.5中添加的,所以它看起来是“历史的”。

我们将不得不询问实际的作者,为什么没有删除多余的声明。话虽如此,在这两个地方都有它并没有负面影响。

不,在两者上都使用iterator方法没有特殊的意义。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56764573

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档