title: Getting values from java.util.Map
body: <p>I have <code>Map&lt;Date, String</code>. I have two Date objects <code>a, b</code> that are equal. I put a string value to the map associated with key <code>a</code>. Then I try to get map value associated with keys <code>a</code> and <code>b</code> but only <code>a</code> returns value that I've put. Is it possible to get my value with <code>b</code> key. I know this is possible when keys are simple strings. Why this doesn't work with other type of objects?</p>
  
  <pre><code>public class Main {
  
  public static void main(String[] args) {
      Map&lt;Date, String&gt; map = new HashMap&lt;Date, String&gt;();
  
      Date a = new Date(20131105);
      Date b = new Date(20131105);
  
      map.put(a, "sweet");
  
      System.out.println(map.get(a));
      System.out.println(map.get(b));
  }
  
  static class Date {
      private int ymd;
  
      public Date(int ymd) {
          this.ymd = ymd;
      }
  
      public int getYmd() {
          return ymd;
      }
  
      @Override
      public boolean equals(Object obj) {
          if (obj instanceof Date) {
              return ((Date) obj).ymd == ymd;
          }
          return false;
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>The output is:</p>
  
  <pre><code>sweet
  null
  </code></pre>