title: What is the hashCode for a custom class having just two int properties?
body: <p>In Java, I have a class that represents a point with int coordinates</p>
  
  <pre><code>public class Point {
      int x = -1;
      int y = -1;
  
      public Point (int xNew, int yNew) {
          x = xNew; y = yNew;
      }
  
      public boolean equals (Object o) {
          // no need for (o instanceof Point) by design
          return x == ((Point)o).x &amp;&amp; y == ((Point)o).y;
      }
  }
  </code></pre>
  
  <p>I'm using objects of class <code>Point</code> as keys in a <code>HashMap</code> and as elements in a <code>HashSet</code>. </p>
  
  <p>What would be the best candidate for the <code>hashCode</code> function? I would make it double so that the left part is x and the right part is y, for example:
  <code>x = 4, y = 12</code>, then the <code>hashCode</code> returns <code>4.12</code>. But by the implementation, it cannot be double, only int.</p>
  
  <p>This is not an option:</p>
  
  <pre><code>public int hashCode() {
      // no need to check for exception parseInt since x and y are valid by design
      return Integer.parseInt(Integer.toString(x) + Integer.toString(y));
  }
  </code></pre>
  
  <p>because values <code>x</code> and <code>y</code> can be too long, so that together they will not be converted.</p>