为什么Java中的很多Collection类都继承了抽象类并实现了接口? [英] Why do many Collection classes in Java extend the abstract class and implement the interface as well?

查看:31
本文介绍了为什么Java中的很多Collection类都继承了抽象类并实现了接口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么Java中的很多Collection类在继承Abstract类的同时还实现了接口(也由给定的抽象类实现)?

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)?

例如HashSet类继承了AbstractSet,也实现了Set,但是AbstractSet已经实现了设置.

For example, class HashSet extends AbstractSet and also implements Set, but AbstractSet already 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.

这篇关于为什么Java中的很多Collection类都继承了抽象类并实现了接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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