title: Objects equal, hashcodes equal, HashSet contains one but not the other---how?
body: <p>I have an (immutable) object, Group, which I am trying to use in a HashSet. However, I am getting odd results:</p>
  
  <pre><code>// Position is another immutable class, GroupType is an enum
  Group t1 = new Group(new Position(0, 0), GroupType.ROW);
  Group t2 = new Group(new Position(0, 0), GroupType.ROW);
  Set&lt;Group&gt; s = new HashSet&lt;Group&gt;();
  s.add(t1);
  System.out.format("t1.hashCode(): %d\nt2.hashCode(): %d\nt1.hashCode() == t2.hashCode(): %b\nt1.equals(t2): %b\nt2.equals(t1): %b\ns.contains(t1): %b\ns.contains(t2): %b\n",
      t1.hashCode(),
      t2.hashCode(),
      t1.hashCode() == t2.hashCode(),
      t1.equals(t2),
      t2.equals(t1),
      s.contains(t1),
      s.contains(t2)
      );
  </code></pre>
  
  <p>results in the following:</p>
  
  <pre><code>t1.hashCode(): 486656595
  t2.hashCode(): 486656595
  t1.hashCode() == t2.hashCode(): true
  t1.equals(t2): true
  t2.equals(t1): true
  s.contains(t1): true
  s.contains(t2): false
  </code></pre>
  
  <p>t1 and t2 have identical hashcodes, and equals() claims that they are the same. How can the HashSet contain one and not the other?</p>
  
  <p>(And no, none of those methods are secretly modifying t1 or t2; repeating the print statement garners the same results.)</p>
  
  <p>Group.equals() is as follows:</p>
  
  <pre><code>public boolean equals(Group g2) {
      return (this.type.equals(g2.type)) &amp;&amp; (this.basis.equals(g2.basis));
  }
  </code></pre>
  
  <p>type is a (final) enum stored. basis is a Position, which has the following equals:</p>
  
  <pre><code>public boolean equals(Position pos) {
      return (x == pos.x) &amp;&amp; (y == pos.y);
  }
  </code></pre>
  
  <p>where x and y are internal, final variables.</p>
  
  <p>However, I get the same results replacing it with:</p>
  
  <pre><code>public boolean equals(Group g2) {
      return true;
  }
  </code></pre>