This question is the result of answers submitted to my post in CodeReview .
I have class, called Point, which is basically "designed to encapsulate a point represented in 2D space." I redefined a function hashcode()that looks like this:
...
@Override
public int hashCode() {
int hash = 0;
hash += (int) (Double.doubleToLongBits(this.getX())
^ (Double.doubleToLongBits(this.getX()) >>> 32));
hash += (int) (Double.doubleToLongBits(this.getY())
^ (Double.doubleToLongBits(this.getY()) >>> 32));
return hash;
}
...
Let me make it clear (for those who have not checked the link above) that mine Pointuses two doubles: xand yto represent its coordinates.
Problem:
My problem is obvious when I run this method:
public static void main(String[] args) {
Point p1 = Point.getCartesianPoint(12, 0);
Point p2 = Point.getCartesianPoint(0, 12);
System.out.println(p1.hashCode());
System.out.println(p2.hashCode());
}
I get the output:
1076363264
1076363264
. , , hashcode() - . (.. Swap 12 1 , Point s), ( ) . , ?