title: Why do different objects with same values cause HashSet.contains to return true?
body: <p>Below is some code that sees if there is a path in a maze from the top-left to the bottom right.  My question with this code is where we check <code>failedPoints.contains(p)</code>: how could we ever get <code>true</code>?</p>
  
  <p>Right before we do <code>if(failedPoints.contains(p))</code> we are creating a new <code>Point</code> object. Even if the new <code>Point</code> object has the same <code>row</code> and <code>col</code> values as another <code>Point</code> in <code>failedPoints</code>, the objects will be different, so shouldn't <code>failedPoints.contains(p)</code> always return <code>false</code>?</p>
  
  <pre><code>boolean getPath(boolean[][] maze, int row, int col, ArrayList&lt;Point&gt; path, HashSet&lt;Point&gt; failedPoints){
     /*if out of bounds or not available, return*/
     if(col&lt;0 || row&lt;0 || !maze[row][col]){
        return false;
     }
     Point p = new Point(row,col);
     /* If we've already visited this cell return*/
     if(failedPoints.contains(p)){
        return false;
     }
  
     boolean isAtOrigin = (row == 0) &amp;&amp; (col == 0);
  
     /*If there's a path from start to my current location, add my location.*/
     if(isAtOrigin || getPath(maze,row,col -1, path, failedPoints) || getPath(maze,row-1, col, path,failedPoints)){
        path.add(p);
        return true;
     }
     failedPoints.add(p); //Cache result
     return false;
  }
  </code></pre>