문서의 선택한 두 판 사이의 차이를 보여줍니다.
양쪽 이전 판 이전 판 다음 판 | 이전 판 마지막 판 양쪽 다음 판 | ||
java:equals_hashcode [2017/07/04 01:01] kwon37xi [Java equals & hashCode] |
java:equals_hashcode [2017/07/04 01:02] kwon37xi [동치 문제의 최종 해결책 canEqual] |
||
---|---|---|---|
줄 59: | 줄 59: | ||
if (other instanceof Point) { | if (other instanceof Point) { | ||
Point that = (Point) other; | Point that = (Point) other; | ||
- | // that.canEqual(this) 가 핵심이다. 이를 거꾸로 | + | // that.canEqual(this) 가 핵심이다. 이를 거꾸로 |
result = (that.canEqual(this) && this.getX() == that.getX() && this.getY() == that.getY()); | result = (that.canEqual(this) && this.getX() == that.getX() && this.getY() == that.getY()); | ||
} | } | ||
줄 77: | 줄 77: | ||
// that.canEqual(this) 호출을 통해서 상위클래스(Point)는 결코 ColoredPoint와 같을 수 없게 보장됨. | // that.canEqual(this) 호출을 통해서 상위클래스(Point)는 결코 ColoredPoint와 같을 수 없게 보장됨. | ||
- | @Override public boolean canEqual(Object other) { | + | @Override |
+ | public boolean canEqual(Object other) { | ||
return (other instanceof ColoredPoint); | return (other instanceof ColoredPoint); | ||
} | } |