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

查看:110
本文介绍了Java.util.HashMap - 为什么HashMap扩展AbstractMap并实现Map?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么HashMap扩展AbstractMap并实现Map?扩展AbstractMap是不够的,因为AbstractMap实现Map吗?

解决方案

它是多余的。我怀疑这是出于文档的原因。 HashMap实现了Map,你可以依赖它。它扩展AbstractMap的事实可以说是一个实现细节。 (尽管未来版本的HashMap不太可能扩展AbstractMap,因为可能存在一些代码,希望HashMap可以分配给AbstractMap。)


why HashMap extends AbstractMap and implement Map ? is extending AbstractMap not sufficient, because AbstractMap implements Map?

解决方案

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天全站免登陆