해시코드가 같으면 equals()메소드를 이용해 객체가 같은지 비교 → 해시코드가 같다고 동일객체가 아닐 수 있음
예제
class Point {
private int x,y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
//public String toString() { //toString 메소드 오버라이딩
//return "Point("+x+", "+y+")";
//}
}
public class ObjectPropertyEx {
public static void print(Object obj) {
System.out.println(obj.getClass().getName());
System.out.println(obj.hashCode()); // 객체 서명 10진수
System.out.println(obj.toString()); // 객체 주소 값 16진수
System.out.println(obj); // 객체 자체를 출력 == toString()
}
public static void main(String[] args) {
Point p = new Point(2,3);
print(p);
}
}