gpt4 book ai didi

java - LinkedHashMap 签名

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:11:28 27 4
gpt4 key购买 nike

查看 LinkedHashMap 的 JDK 源代码,我注意到这个类被声明为:

 public class LinkedHashMap<K,V>
extends HashMap<K,V>
implements Map<K,V>
{...

为什么多余的“implements Map<K,V>”(因为 HashMap 已经实现了 Map)?我无法想象这是一个错字...

谢谢。

最佳答案

我想这是一种表达方式

No matter what interfaces HashMap implements (now or in the future), this class should implement the Map interface.

如果负责 HashMap 的人决定不再实现 Map 接口(interface),编译器将警告 LinkedHashMap 的维护者它不再按照他的意图实现 Map 接口(interface)。

当然,在这种特殊情况下这很愚蠢(HashMap 显然总是一个 Map),但类似的情况可能会受益于(并产生)这种约定。

关于java - LinkedHashMap 签名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3438864/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com