2023-java-study / book-study

북 스터디 기록 레포지토리
0 stars 0 forks source link

[Item 11] 파생 필드는 hashcode 계산에서 제외해도 되는 이유 #35

Closed gmelon closed 1 year ago

gmelon commented 1 year ago

p.69 에 파생 필드는 hashcode 계산에서 제외해도 되는 이유 가 어차피 이미 다른 필드를 통해 hashcode가 계산될 것이기 때문에 파생 필드를 통해 hashcode를 업데이트한다고 해도 두 인스턴스간에 만들어질 hashcode는 변화가 없을 것이기 때문일까요??

gmelon commented 1 year ago

int 원래필드 = 10; int 파생필드 = 원래필드 / 10;

hashcode() { 원래필드 + 파생필드 }

hashcode() { 원래필드 }