AbstractCollection
实现了 Iterable
和 Collection
接口(interface)。但是,Collection
是 Iterable
的子接口(interface)。仅仅让 AbstractCollection
实现 Collection
还不够吗?
最佳答案
Javadocs for AbstractCollection
可以解释为 AbstractCollection
直接 实现了 Collection
和 Iterable
。
All Implemented Interfaces:
Iterable, Collection
然而,a quick look at the source code表明它只直接实现Collection
。
public abstract class AbstractCollection<E> implements Collection<E> {
因此,必须将 Javadoc 解释为类直接或间接实现了给定的接口(interface)。正如您所指出的,AbstractCollection
不需要直接实现 Iterable
,因为它已经实现了 Collection
。源代码显示它没有直接实现Iterable
。 AbstractCollection
仅直接实现 Collection
就足够了。
关于java - 为什么 AbstractCollection 同时实现了 Iterable 和 Collection?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30584592/