gpt4 book ai didi

java - 为什么 AbstractCollection 同时实现了 Iterable 和 Collection?

转载 作者:行者123 更新时间:2023-11-29 03:08:50 24 4
gpt4 key购买 nike

AbstractCollection 实现了 IterableCollection 接口(interface)。但是,CollectionIterable子接口(interface)。仅仅让 AbstractCollection 实现 Collection 还不够吗?

最佳答案

Javadocs for AbstractCollection可以解释为 AbstractCollection 直接 实现了 CollectionIterable

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。源代码显示它没有直接实现IterableAbstractCollection 仅直接实现 Collection 就足够了。

关于java - 为什么 AbstractCollection 同时实现了 Iterable 和 Collection?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30584592/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com