반응형 hashCode1 equals 와 hashCode의 재정의를 같이 해야하는 이유 먼저 아래와 같이 클래스를 정의해두고 public class Person { private final String name; public Person(String name) { this.name = name; } // intellij Generate 기능 사용 @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Person person = (Person) o; return Objects.equals(name, person.name); } } person클래스에서는 equals만 재정의를 하였고 이어서 생성을 해보았다. pub.. 2022. 4. 26. 이전 1 다음 반응형