title: What are the benefits of declaring an object as interface?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/383947/what-does-it-mean-to-program-to-an-interface">What does it mean to &ldquo;program to an interface&rdquo;?</a>  </p>
  </blockquote>
  
  
  
  <p>I noticed that some people like to declare an object as one of the interfaces it implements <strong>even though, within the scope of the variable, it is not necessary to look at it as the interface</strong>, e.g. there is no external API that expect an interface.</p>
  
  <p>For example:</p>
  
  <pre><code>Map&lt;String, Object&gt; someMap = new HashMap&lt;String, Object&gt;();
  </code></pre>
  
  <p>Or you can just do</p>
  
  <pre><code>HashMap&lt;String, Object&gt; someMap = new HashMap&lt;String, Object&gt;();
  </code></pre>
  
  <p>and avoid importing <code>java.util.Map</code> altogether.</p>
  
  <p>What are the advantages of declaring it through an interface (first above) as opposed to the class itself (second above)?</p>
  
  <p>Thanks</p>