What is the difference between the HashMap and Map objects in Java?

后端 未结 13 1343
无人及你
无人及你 2020-11-22 17:07

What is the difference between the following maps I create (in another question, people answered using them seemingly interchangeably and I\'m wondering if/how they are diff

13条回答
  •  清歌不尽
    2020-11-22 17:32

    You create the same maps.

    But you can fill the difference when you will use it. With first case you'll be able to use special HashMap methods (but I don't remember anyone realy useful), and you'll be able to pass it as a HashMap parameter:

    public void foo (HashMap m1 = ...;
    Map m2 = ...;
    
    foo (m1);
    foo ((HashMap)m2); 
    

提交回复
热议问题