-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPoint.java
More file actions
39 lines (31 loc) · 715 Bytes
/
Point.java
File metadata and controls
39 lines (31 loc) · 715 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package testingEquals;
public class Point {
private int x;
private int y;
public Point(int x, int y) {
super();
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public boolean equals(Object obj) {
if (!(obj instanceof Point)) return false;
if (isEqualsInDifferentClass(obj)) return obj.equals(this);
Point other = (Point) obj;
if (x != other.x) return false;
if (y != other.y) return false;
return true;
}
final protected boolean isEqualsInDifferentClass(Object obj) {
try {
return ! getClass().equals(obj.getClass().getMethod("equals", Object.class).getDeclaringClass());
} catch (Exception e) {
return false;
}
}
}