title: Java hashCode for a Point class
body: <p>I have a simple custom Point class as follows and I would like to know if my hashCode implemention could be improved or if this is the best it's going to get.</p>
  
  <pre><code>public class Point 
  {
      private final int x, y;
  
      public Point(int x, int y)
      {
          this.x = x;
          this.y = y;
      }
  
      public int getX() 
      {
          return x;
      }
  
      public int getY()
      {
          return y;
      }
  
      @Override
      public boolean equals(Object other) 
      {
          if (this == other)
            return true;
  
          if (!(other instanceof Point))
            return false;
  
          Point otherPoint = (Point) other;
          return otherPoint.x == x &amp;&amp; otherPoint.y == y;
      }
  
  
      @Override
      public int hashCode()
      {
          return (Integer.toString(x) + "," + Integer.toString(y)).hashCode();
      }
  
  }
  </code></pre>