hashmap에서 object를 key로 설정 시 주의사항
HashMap은 키값을 내부적으로 hashCode의 리턴값을 이용하여 관리합니다. put할 때 hashCode를 호출하여 기존에 들어있는 키 중에서 hashCode 값이 같은 것이 있는 지를 먼저 검사합니다 . 키가 같은 것이 있다면, 그다음에 equals를 호출하여, 정말로 같은 키인지를 판단합니다 . 그렇기 때문에 equals를 호출해서 true가 리턴되는 경우라도 hashCode가 다른 값을 리턴하면 안 됩니다. hashCode가 먼저 호출되기 때문이지요. @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((id == null) ? 0 : id.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; SiteInfo other = (SiteInfo) obj; if (id == null) { if (other.id != null) return false; } else if (!id.equals(other.id)) return false; if (name == null) { if (other.name != null) return false; } else if (!name.eq...