why HashMap extends AbstractMap and implement Map ? is extending AbstractMap not sufficient, because AbstractMap implements Map?
-
1essentially the same question as this: http://stackoverflow.com/questions/2165204/why-does-linkedhashsete-extend-hashsete-and-implement-sete -- short version: this redundancy has an impact on how Javadoc gets generated. – Kevin Bourrillion Feb 19 '10 at 17:29
-
I was spurred to investigate, and actually, Javadoc was not the issue. New short version: it was just a mistake. – Kevin Bourrillion Feb 19 '10 at 17:41
-
Heh. I asked about this today too. I was told that it was a "well-intentioned mistake", and that the original reasoning was the interface versus implementation thing I mentioned in my answer. – Laurence Gonsalves Feb 20 '10 at 02:09
3 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.)

- 137,896
- 35
- 246
- 299
It is redundant, but doesn't hurt. If they do not want to implement Map
in AbstractMap
in future, it will still work.

- 39,895
- 28
- 133
- 186
-
3Except that's a breaking change - somewhere someone will have done `Map map=objectOfTypeAbstractMap`. – Lawrence Dol Feb 19 '10 at 08:26
One more thing is that AbstractMap is an implementation detail. It could be absent in a future version of Oracle's JDK.. It could be absent in a current version of IBM's JDK.. But whether it is present or not, the HashMap should always conform to the List contract.. So, it is explicitly captured in class declaration by specifying 'HashMap implements Map'

- 1,983
- 3
- 14
- 26