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 它的完整的类层级关系。