title: Why is the variable declared as Map and initialized as HashMap; aren't they different types?
body: <p>Let's say I want to make a <code>HashMap</code> of grades.</p>
  
  <pre><code> Map&lt;String,Integer&gt; grades = new HashMap&lt;String,Integer&gt;(); 
   grades.put("John", 87); // this work due to auto-boxing right?
   grades.put("Luke", Integer(85)); // non-autoboxed, is this redundant? 
  </code></pre>
  
  <p>Why is Map on the left and <code>HashMap&lt;K, V&gt;( );</code> on the right? Isn't it pretty much a rule that you need type consistency whenever you create an object? Unless the static type of names is Map and the dynamic type is <code>HashMap</code>, which presumably is a subclass of <code>Map</code>. But why would you want to do this? Method calls are called from the perspective of an objects static type (e.g <code>Map</code>s), but if there are overridden methods in the dynamic type, those methods will be called. Is this why the types are different?</p>
  
  <p>Thanks! Newbie question but this stuff can be confusing...</p>
  
  <p>EDIT:</p>
  
  <p>Thanks! So the general format is: Interface varName = new ImplementedClassConstructor(); ? And we often choose a superclass Interface because it allows easier substitution later (e.g. if I wanted to change HashMap to TreeMap? </p>