HashMap的大神也有小遗忘

138 阅读1分钟

最近看源码,发现一个有意思的代码。

HashMap 继承 AbstractMap,实现Map接口。 AbstractMap本身也实现Map接口。 那么这个设计是为什么讷?

  public class HashMap<K,V> extends AbstractMap<K,V>
    implements Map<K,V>, Cloneable, Serializable 

  public abstract class AbstractMap<K,V> implements Map<K,V> 

有人回答,覆盖啊,重新覆盖啊。一堆高大上的解释。

其实,原因往往非常简单。大神也是人。也是程序员。只是作者没在意,遗忘了,后来也没有去掉,因为不算什么大事儿,就没有改动。这就是原因。惊不惊喜,意不意外。

😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂