本文介绍了为什么 LinkedHashSet<E>扩展 HashSet<e>并实施 Set<E>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
今天打开了一个LinkedHashSet的源码,发现了一些有趣的东西:
Opened a LinkedHashSet source code today and found some interesting thing:
public class LinkedHashSet<E>
extends HashSet<E>
implements Set<E>, Cloneable, java.io.Serializable {
问题是:当 HashSet 已经是 Set 时,为什么他们需要extends HashSet"和implements Set"?
The question is: why do they need both "extends HashSet" and "implements Set" when HashSet already is the Set?
推荐答案
我问过 Josh Bloch,他告诉我这是一个错误.很久以前,他曾经认为它有一些价值,但后来他看到了曙光".显然 JDK 维护者认为这不值得以后退出.
I've asked Josh Bloch, and he informs me that it was a mistake. He used to think, long ago, that there was some value in it, but he since "saw the light". Clearly JDK maintainers haven't considered this to be worth backing out later.
这篇关于为什么 LinkedHashSet<E>扩展 HashSet<e>并实施 Set<E>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!