为什么ArrayList有“implements List”? [英] Why does ArrayList have "implements List"?

查看:267
本文介绍了为什么ArrayList有“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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆