본문 바로가기
Backend

롬복 A class Builder is not compatible in class B Builder

by GOMJ 2024. 6. 30.

스프링 기반 서버 개발을 하다보면 롬복을 종종 사용하게 된다.

 

그 중 상속 클래스를 활용하면서 발생했던 에러가 있었습니다.

A class Builder is not compatible in class B Builder

 

A Class에 @Builder annotation을 상요하고 A 를 Extends 하는 B Class에서도 @Builder annotation을 사용했다.

 

그리고 빌드를 하니 위와 같은 에러 문구가 발생했습니다.

 

해당 오류의 원인은 확장하려는 Class에 @Builder annotation을 사용하고 상속 Class 에 또 @Builder를 사용하면 발생하는 오류였다.

 

해결 방법은 의외로 간단했다. @Builder를 @SuperBuilder로 변경해주면 끝이다.

 

예시는 다음과 같다.

@Data
@SuperBuilder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class CommonReviewDtoWithOutChilds {
    private Long id;
    private Long parentId;
    private Long performanceId;
    private Long userId;
    private String profileImageUrl;
    private String nickname;
    private String title;
    private float starScore;
    private String createdDate;
    private String content;
    private List<String> images = new ArrayList<>();
    private Long hit;
    private Long reviewCount;
}

 

@Data
@SuperBuilder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class CommonReviewDto extends CommonReviewDtoWithOutChilds{
    private List<CommonReviewDto> childs = new ArrayList<>();

    public CommonReviewDto(Long id, Long parentId, Long performanceId, Long userId, String profileImageUrl, String nickname, String title, float starScore, String createdDate, String content, List<String> images, Long hit, Long reviewCount, List<CommonReviewDto> childs) {
        super(id, parentId, performanceId, userId, profileImageUrl, nickname, title, starScore, createdDate, content, images, hit, reviewCount);
        this.childs = childs;
    }
}

'Backend' 카테고리의 다른 글

@JsonFormat 과 @DateTimeFormat  (0) 2024.07.14
[Spring] DispatcherServlet  (0) 2024.07.07
[DB]ORM이란?  (0) 2024.06.30
3-Tier, 3계층 Architecture구조  (1) 2024.06.23
Stateful과 Stateless  (0) 2024.06.23