Java.util.HashMap -- why HashMap extends AbstractMap and implement Map?(Java.util.HashMap -- 为什么 HashMap 扩展 AbstractMap 并实现 Map?)
问题描述
为什么 HashMap 扩展 AbstractMap 并实现 Map ?扩展 AbstractMap 是否不够,因为 AbstractMap 实现了 Map?
why HashMap extends AbstractMap and implement Map ? is extending AbstractMap not sufficient, because AbstractMap implements Map?
推荐答案
这是多余的.我怀疑这是出于文档"的原因.HashMap 实现了 Map,你可以依赖它.它扩展 AbstractMap 的事实可以说只是一个实现细节.(尽管 HashMap 的未来版本不太可能不扩展 AbstractMap,因为可能有一些代码期望 HashMap 可以分配给 AbstractMap.)
It is redundant. I suspect that it was done for "documentation" reasons. HashMap implements Map, and you can rely on that. The fact that it extends AbstractMap is arguably just an implementation detail. (Though it's extremely unlikely that future versions of HashMap would not extend AbstractMap, since there probably some code out there that expects HashMap to be assignable to AbstractMap.)
这篇关于Java.util.HashMap -- 为什么 HashMap 扩展 AbstractMap 并实现 Map?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Java.util.HashMap -- 为什么 HashMap 扩展 AbstractMap 并实


基础教程推荐
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 存储 20 位数字的数据类型 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01