问题描述
在集合框架中,我们有接口 List
和类 AbstractList
:
In the Collection Framework we have the interface List
and the class AbstractList
:
AbstractList implements List
和 ArrayList
扩展了 AbstractList
和
implements List
我的问题:为什么 ArrayList
有 implements List
子句?
My question: why does ArrayList
have the implements List
clause?
如果ArrayList继承了AbstractList
,而AbstractList实现了List
,那不是说ArrayList实现了List
吗?
If ArrayList extends AbstractList
and AbstractList implements List
, can't we say, that ArrayList implement List
?
推荐答案
是的.本来可以省略的.但是因此可以立即看出它是一个 List
.否则需要额外点击代码/文档.我认为这就是原因 - 清晰.
Yes. It could've been omitted. But thus it is immediately visible that it is a List
. Otherwise an extra click through the code / documentation would be required. I think that's the reason - clarity.
并添加 Joeri Hendrickx 评论的内容 - 这是为了表明 ArrayList
实现了 List
.AbstractList
全图只是为了方便和减少 List
实现之间的代码重复.
And to add what Joeri Hendrickx commented - it is for the purpose of showing that ArrayList
implements List
. AbstractList
in the whole picture is just for convenience and to reduce code duplication between List
implementations.
这篇关于为什么 ArrayList 有“实现列表"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!