My Usage:
-
Bean:
@Builder
,@NoArgsConstructor
,@Setter
,@Getter
,@Data
-
Service/Component:
@Slf4j
,@RequiredArgsConstructor
Because I heavily use JSON in my application, I generally need a no-args constructor in the beans.
Notes:
-
@Builder
can't work with only@NoArgsConstructor
; it also requires@AllArgsConstructor
. -
@SuperBuilder
works only with@NoArgsConstructor
and without@AllArgsConstructor
. - Using
@Builder
on a superclass and@SuperBuilder
on the subclass works, but only the superclass instance is built.
Best Practices:
- Prefer
@SuperBuilder
over@Builder
when working with inheritance.
Top comments (0)