If you want objects with different ids to identified by that id all you need to do is return it/compare it.
private final int id;
public int hashCode() { return id; }
public boolean equals(Object o) {
return o instanceof ThisClass && id == ((ThisClass)o).id;
}