title: How to make HashMap work properly with custom key type?
body: <p>I think my question is quite simple, however I couldn't find the solution so I decided to ask here. What i need is to make a <code>HashMap</code> with a custom Key type like this:</p>
  
  <pre><code>HashMap&lt;Pair&lt;Integer, Integer&gt;, StrategyPoint&gt; myMap = new HashMap&lt;Pair&lt;Integer, Integer&gt;, StrategyPoint&gt; ();
  </code></pre>
  
  <p>However I am missing something here, because the <code>HashMap</code> stops working properly. First the Key becomes not unique and a different instances of Pair with same values can be found in the <code>keySet</code>. Also the contains key function does not work the way I suppose it to :).</p>
  
  <p>I clearly miss something and more likely I should somehow define a way to compare my instances from my <code>Pair</code> class. However I tried implementing Comparable with <code>compareTo</code> in my <code>Pair</code> class and it still don't work. Any suggestions?</p>
  
  <p>My original code is kinda messy and unfriendly to read, so I made an example just to illustrate my problem here.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>HashMap&lt;Pair&lt;Integer, Integer&gt;, StrategyPoint&gt; myMap = new HashMap&lt;Pair&lt;Integer, Integer&gt;, StrategyPoint&gt; ();
      Pair&lt;Integer, Integer&gt; myPair = new Pair&lt;Integer, Integer&gt;(2,2);
      StrategyPoint myPoint= new StrategyPoint(2, 2, 5, 5, false);
      myMap.put(myPair, myPoint);
  
  
      Pair&lt;Integer, Integer&gt; searcher = new Pair&lt;Integer, Integer&gt; (0,0);
      searcher.setFirst(2);
      searcher.setSecond(2);
      System.out.println(myMap.containsKey(searcher));
      System.out.println(myMap.containsKey(myPair));
  </code></pre>
  
  <p>The result from execution is:</p>
  
  <pre><code>false
  
  true
  </code></pre>
  
  <p>I have debug it and the searcher instance is being populated properly, however it seems the <code>HashMap</code> refuse to find it in its <code>keySet</code>.</p>