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:
-
@Buildercan't work with only@NoArgsConstructor; it also requires@AllArgsConstructor. -
@SuperBuilderworks only with@NoArgsConstructorand without@AllArgsConstructor. - Using
@Builderon a superclass and@SuperBuilderon the subclass works, but only the superclass instance is built.
Best Practices:
- Prefer
@SuperBuilderover@Builderwhen working with inheritance.
Top comments (0)