[Spring] warning: Generating equals/hashCode implementation but without a call to superclass, even though this class does not extend java.lang.Object. If this is intentional, add '@EqualsAndHashCode(callSuper=false)' to your type.

2024. 6. 10. 00:45·Spring

* User class의 @Data에서 warning 발견

  • warning: Generating equals/hashCode implementation but without a call to superclass, even though this class does not extend java.lang.Object. If this is intentional, add '@EqualsAndHashCode(callSuper=false)' to your type.

* 해결 방법

 - @EqualsAndHashCode(callSuper = true) or @EqualsAndHashCode(callSuper = false) 추가

  • @Data 에는 @Getter, @Setter, @RequiredArgsConstructor, @ToString, @EqualsAndHashCode가 포함되어 있다.
    • @Getter : 모든 필드에 대한 getter 메서드를 생성한다.
    • @Setter : 모든 필드에 대한 setter 메서드를 생성한다.
    • @RequiredArgsConstructor : final 필드 및 @NonNull 필드에 대한 생성자 생성한다.
    • @ToString : 모든 필드를 포함하는 toString 메서드를 생성한다.
    • @EqualsAndHashCode : 모든 필드를 기준으로 equals 및 hashCode 메서드를 생성한다.
      • equals와 hashCode는 모든 Java 객체의 부모 객체인 Object 클래스에 정의되어 있다. 
        • equals 메서드는 두 객체가 동일한 데이터를 가지고 있는지 비교합니다. ( 동일성 비교 ) 
        • hashCode 메서드는 객체의 해시 코드를 반환하며, 객체를 빠르게 찾기 위해 사용됩니다. 만약 equals 메서드가 두 객체를 동일하다고 판단하면 두 객체의 해시 코드도 동일합니다.
  • 왜 @EqualsAndHashCode(callSuper = true)를 작성해야 할까?
    • 부모 클래스의 필드도 동등성 비교에 포함할지 말지를 결정해야 하기 때문이다. 상속 계층이 있는 클래스에서 @Data 를 사용하게 되면 부모 클래스의 필드를 포함하여 동등성을 비교할지 판단해 줘야 한다.

* 해결 완료!

 

 

References

    • https://mangkyu.tistory.com/101

 

'Spring' 카테고리의 다른 글

[Spring] Spring Security OAuth2 - 인증 및 인가 흐름 요약  (0) 2024.07.21
[Spring] AWS RDS - Spring boot ( MariaDB ) 프로젝트 연결 (2)  (0) 2024.06.02
'Spring' 카테고리의 다른 글
  • [Spring] Spring Security OAuth2 - 인증 및 인가 흐름 요약
  • [Spring] AWS RDS - Spring boot ( MariaDB ) 프로젝트 연결 (2)
밀27
밀27
  • 밀27
    밀2
    밀27
    • 분류 전체보기 (35)
      • Git (1)
      • AWS (1)
      • Flutter (3)
      • Spring (3)
      • MariaDB (2)
      • TIL (25)
      • Daily (0)
  • 블로그 메뉴

    • 홈
    • 태그
  • 최근 글

  • hELLO· Designed By정상우.v4.10.0
밀27
[Spring] warning: Generating equals/hashCode implementation but without a call to superclass, even though this class does not extend java.lang.Object. If this is intentional, add '@EqualsAndHashCode(callSuper=false)' to your type.
상단으로

티스토리툴바