title: HashSet contains() returns false for custom object. hashCode() and equals() seem to be implemented correctly
body: <p>I have the following simple Rectangle class. If two rectangles have the same height and width, they are equal and have the same hashcode. I added a new rectangle to a hashSet.</p>
  
  <pre><code>Set&lt;Rectangle&gt; set = new HashSet&lt;Rectangle&gt;();
  set.add(new Rectangle(3,3));
  </code></pre>
  
  <p>When I try to call contains on a new rectangle with same height and width, it returns false.</p>
  
  <p><code>set.contains(new Rectangle(3,3))</code> returns false. I can't figure out why. Any ideas?</p>
  
  <pre><code>   public class Rectangle implements Comparable&lt;Rectangle&gt; {
              final int height, width, area, minimumEdge, maximumEdge;
  
              public Rectangle(int height, int width) {
                  this.height = height;
                  this.width = width;
                  area = height * width;
                  maximumEdge = height &gt; width ? height : width;
                  minimumEdge = height &lt; width ? height : width;
              }
  
              public int compareTo(Rectangle rect2) {
                  if (rect2.minimumEdge &gt; this.minimumEdge) {
                      return -1;
                  } else if (rect2.minimumEdge &lt; this.minimumEdge) {
                      return 1;
                  } else {
                      return 0;
                  }
              }
  
              public int hashCode(){
                  return ((width + height)*31);
              }
  
              public boolean equals(Rectangle rect2){
                  return (this.height == rect2.height &amp;&amp; this.width == rect2.width);
              }
          }
  </code></pre>