您的位置:首页 > 编程语言 > Java开发

Why do many Collection classes in Java extend the abstract class and implement the interface as well

2016-09-20 19:51 525 查看
Why do many Collection classes in Java extend the Abstract class and also implement the interface (which is also implemented by the given abstract class)?

For example,
class 
HashSet
 extends 
AbstractSet
 and
also implements 
Set
, but 
AbstractSet
already
implements 
Set
.

为什么 许多Collection 类 既继承了抽象类 也实现了 接口,如 HashSet extends AbstractSet implements Set,且 AbstractSet implements Set ?

It's a way to remember that this class really implements that interface.
It won't have any bad effect and it can help to understand the code without going through the complete hierarchy of the given class.

这种方式有助于记忆该类确实实现了该接口

这并没有什么坏处,这有助于我们理解代码 而不用去 check 它的完整的类层级关系。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐