Java.util.HashMap -- 为什么 HashMap 扩展 AbstractMap 并实现 Map? [英] Java.util.HashMap -- why HashMap extends AbstractMap and implement Map?

查看:22
本文介绍了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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆