Annotation Type SuperBuilder
The SuperBuilder annotation creates a so-called 'builder' aspect to the class that is annotated with
@SuperBuilder
, but which works well when extending.
It is similar to @Builder
, except it is only legal on types, is less configurable, but allows you to extends
other builder-able classes.
All classes in the hierarchy must be annotated with @SuperBuilder
.
Lombok generates 2 inner 'builder' classes, which extend the parent class' builder class (unless your class doesn't have an extends clause).
Lombok also generates a static method named builder()
, and a protected constructor that takes 1 argument of the builderclass type.
The TBuilder
class contains 1 method for each parameter of the annotated
constructor / method (each field, when annotating a class), which returns the builder itself.
The builder also has a build()
method which returns a completed instance of the original type.
Complete documentation is found at the project lombok features page for @SuperBuilder.
- See Also:
-
Optional Element Summary
Modifier and TypeOptional ElementDescriptionPrefix to prepend to 'set' methods in the generated builder class.boolean
Iftrue
, generate an instance method to obtain a builder that is initialized with the values of this instance.
-
Element Details
-
builderMethodName
String builderMethodName- Returns:
- Name of the method that creates a new builder instance. Default:
builder
. If the empty string, suppress generating thebuilder
method.
- Default:
"builder"
-
buildMethodName
String buildMethodName- Returns:
- Name of the method in the builder class that creates an instance of your
@Builder
-annotated class.
- Default:
"build"
-
toBuilder
boolean toBuilderIftrue
, generate an instance method to obtain a builder that is initialized with the values of this instance. In this case, all superclasses must also havetoBuilder=true
.- Returns:
- Whether to generate a
toBuilder()
method.
- Default:
false
-
setterPrefix
String setterPrefixPrefix to prepend to 'set' methods in the generated builder class. By default, generated methods do not include a prefix. For example, a method normally generated assomeField(String someField)
would instead be generated aswithSomeField(String someField)
if using@SuperBuilder(setterPrefix = "with")
. Note that using "with" to prefix builder setter methods is strongly discouraged as "with" normally suggests immutable data structures, and builders by definition are mutable objects. For@Singular
fields, the generated methods are calledwithName
,withNames
, andclearNames
, instead of the defaultname
,names
, andclearNames
. This prefix only applies to the 'set' methods for the fields of the annotated class. For consistency reasons, you should use the same prefix on all superclasses and subclasses that use@SuperBuilder
.- Returns:
- The prefix to prepend to generated method names.
- Default:
""
-