title: Is it better to return an ImmutableMap or a Map?
body: <p>Let's say I'm writing a method that should return a <a href="https://docs.oracle.com/javase/7/docs/api/java/util/Map.html">Map</a>. For instance:</p>
  
  <pre><code>public Map&lt;String, Integer&gt; foo() {
    return new HashMap&lt;String, Integer&gt;();
  }
  </code></pre>
  
  <p>After thinking about it for a while, I've decided that there is no reason to modify this Map once it is created. Thus, I would like to return an <a href="https://google.github.io/guava/releases/snapshot/api/docs/com/google/common/collect/ImmutableMap.html">ImmutableMap</a>.</p>
  
  <pre><code>public Map&lt;String, Integer&gt; foo() {
    return ImmutableMap.of();
  }
  </code></pre>
  
  <p><b> Should I leave the return type as a generic Map, or should I specify that I'm returning an ImmutableMap ? </b>
  <br><br>
  From one side, this is exactly why interfaces were created for; to hide the implementation details.
  <br> 
  On the other hand, if I'll leave it like this, other developers might miss the fact that this object is immutable. Thus, I won't achieve a major goal of immutable objects; to make the code more clear by minimizing the number of objects that can change. Even worst, after a while, someone might try to change this object, and this will result in a runtime error (The compiler will not warn about it).</p>