Possible Duplicate:
Java.util.HashMap — why HashMap extends AbstractMap and implement Map?
In java to implement HashMap<K,V> we need to implement Map<K,V>.
However when I debugged more in java classes it seems that…. java defines HashMap class as following.
public class HashMap<K,V>
extends AbstractMap<K,V>
implements Map<K,V>, Cloneable, Serializable
At the same time i saw public abstract class AbstractMap<K,V> implements Map<K,V> it also implements the interface Map<K,V>.
If abstract class implements the interface then, what is the reason behind implementing Map<K,V> at HashMap class level?
As per my understanding HashMap class have all the methods inherited from AbstractMap which can be overridden by HashMap as per the requirement.
I believe the reasoning behind this is an abstract class in Java need not declare/implement all the methods in the interface.
Thus
the following abstract implementation of the interface is valid.
Thus I believe in order to be explicit about
HashMapimplementing the methods not implemented by the abstract class it is shown to implement the interfaceMapwhereas it is completely optional to do so because any implementation of the abstract class needs to implement all the methods either in the abstract class or the derived base class..Thus in the above example a valid implementation to the abstract class is
which you can rewrite as follows too: