Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java.util.HashMap -- why HashMap extends AbstractMap and implement Map? [duplicate]

Tags:

java

hashmap

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

like image 598
SomaSekhar Avatar asked Feb 19 '10 06:02

SomaSekhar


1 Answers

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.)

like image 64
Laurence Gonsalves Avatar answered Nov 15 '22 22:11

Laurence Gonsalves