Item 11. equals를 오버라이딩할 거면 hashCode도 오버라이딩하라
hashCode
public int hashCode() {}hashCode를 오버라이딩해야 할 때?
hashCode 오버라이딩의 좋은 예
전통적인 구현 방식
@Override
public int hashCode() {
int result = 0;
result = 31 * result + Integer.hashCode(number);
result = 31 * result + String.hashCode(string);
...
return result;
}Guava의 Hashing을 이용하는 방법
Objects의 hash 메서드를 이용하는 방법
AutoValue 프레임워크를 이용하거나 IDE에서 자동으로 생성해주는 hashCode를 이용
Last updated