为什么 AbstractCollection 同时实现了 Iterable 和 Collection?
Why does AbstractCollection implement both Iterable and Collection?
AbstractCollection
实现了 Iterable
和 Collection
接口。但是,Collection
是 Iterable
的 子接口 。仅让 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 解释为 class 直接 或间接 实现了给定的接口。正如您所指出的,AbstractCollection
不需要直接实现 Iterable
,因为它已经实现了 Collection
。源代码显示它没有直接实现 Iterable
。 AbstractCollection
直接实现 Collection
就足够了。
是的。就足够了。但是,明确列出两者允许人们告诉(通过简单检查)AbstractCollection
实现了 Iterable
和 Collection
(另外,因为它是 abstract
,它不一定实现任何一个接口 - 但任何具体的子 class 都会)。
AbstractCollection
实现了 Iterable
和 Collection
接口。但是,Collection
是 Iterable
的 子接口 。仅让 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 解释为 class 直接 或间接 实现了给定的接口。正如您所指出的,AbstractCollection
不需要直接实现 Iterable
,因为它已经实现了 Collection
。源代码显示它没有直接实现 Iterable
。 AbstractCollection
直接实现 Collection
就足够了。
是的。就足够了。但是,明确列出两者允许人们告诉(通过简单检查)AbstractCollection
实现了 Iterable
和 Collection
(另外,因为它是 abstract
,它不一定实现任何一个接口 - 但任何具体的子 class 都会)。