我的java版本是"1.8.0_192“
/**
* 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();这是集合接口。
/**
* Returns an iterator over elements of type {@code T}.
*
* @return an Iterator.
*/
Iterator<T> iterator();这是Iterable接口。
发布于 2019-06-26 11:09:42
真的没有理由两者兼而有之。如果你看一下Collection的since部分,你会发现它是在1.2中添加的,而Iterable是在1.5中添加的,所以它看起来是“历史的”。
我们将不得不询问实际的作者,为什么没有删除多余的声明。话虽如此,在这两个地方都有它并没有负面影响。
不,在两者上都使用iterator方法没有特殊的意义。
https://stackoverflow.com/questions/56764573
复制相似问题