Skip to content

아이템 2. 생성자에 매개변수가 많다면 빌더를 고려하라. #21

Answered by chikeem90
YuDeokRin asked this question in 3. 과제
Discussion options

You must be logged in to vote

롬복(Lombok)을 사용한다! → @builder

오,, 롬복까지 같이 정리해주셨네요 👍
말씀해주신대로 롬복의 단점이 필수 값을 지정할 수는 없어서,, 그 부분을 조금 유의해야할 거 같습니다.
추가로 Builder 애노테이션을 쓰면 @Builder.Default로 디폴트값을 지정해줄 수 있습니다.
만약의 필수값인데 빌더 생성 시 누락 했을때 기본값이 세팅되도록,, 그렇게 단점을 살짝 극복할 수 있을 거 같긴 하네요.

@Builder
public class ProductsStockApiRequest {
    @Builder.Default
    List<ProductStockApiRequest> products = List.of();
}

https://projectlombok.org/features/Builder

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by YuDeokRin
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
2장 객체 생성과 파괴 이펙티브 자바 2장 (객체 생성과 파괴)
2 participants