为什么ArrayList有“implements List”? [英] Why does ArrayList have "implements List"?
问题描述
在Collection框架中,我们有 List
和 AbstractList
接口:
AbstractList implements List
ArrayList
extends AbstractList
和
implements List
我的问题:为什么 ArrayList $如果
具有
implements List 子句?
和 AbstractList implements List
,我们不能说, ArrayList实现List
? >
解决方案是的。它可以被省略。但是因此立即可以看到它是 List
。否则,将需要额外点击代码/文档。我认为这是原因 - 清晰。
并且添加Joeri Hendrickx评论 - 这是为了显示 ArrayList
implements List
。 AbstractList
在整个图片只是为了方便,并减少列表
实现之间的代码重复。
In the Collection Framework we have the interface List
and the class AbstractList
:
AbstractList implements List
And ArrayList
extends AbstractList
and
implements List
My question: why does ArrayList
have the implements List
clause?
If ArrayList extends AbstractList
and AbstractList implements List
, can't we say, that ArrayList implement 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.
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有“implements List”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!