class A{}
public class Test {
public static void main(String[] args) {
A a = new A();
System.out.printf("%x",a.hashCode());
}
}
System.out.println(Objects.hash(1,2,3));
클래스내에서 hashCode,equals를 오버라이딩을 하여 hash값을 맞춰줄 수 있다.
class A{
int data;
public A(int data){
this.data = data;
}
@Override
public boolean equals(Object obj) {
if(obj instanceof A){
this.data = ((A)obj).data;
return ture;
}
return false;
}
@Override
public int hashCode() {
return Objects.hash(data);
}
}