From b37f3cba3eb7e7babd38894b890ca5fda2f57cf4 Mon Sep 17 00:00:00 2001
From: Jan Rieke @SuperBuilder
was introduced as experimental feature in lombok v1.18.2.
@SuperBuilder
's toBuilder
feature and limited support for customization was added with lombok v1.18.4.
+
+ @SuperBuilder
customization possibilities were extended with lombok v1.18.14.
The @SuperBuilder
annotation produces complex builder APIs for your classes.
In contrast to @Builder
, @SuperBuilder
also works with fields from superclasses.
- However, it only works for types, and customization possibilities are limited.
+ However, it only works for types.
Most importantly, it requires that all superclasses also have the @SuperBuilder
annotation.
@SuperBuilder
lets you automatically produce the code required to have your class be instantiable with code such as:
@@ -21,7 +23,7 @@
@SuperBuilder
can generate so-called 'singular' methods for collection parameters/fields. For details, see the @Singular
documentation in @Builder
.
- @SuperBuilder
generates a private constructor on the class that takes a builder instance as a parameter. This constructor sets the fields of the new instance to the values from the builder.
+ @SuperBuilder
generates a protected constructor on the class that takes a builder instance as a parameter. This constructor sets the fields of the new instance to the values from the builder.
@SuperBuilder
is not compatible with @Builder
.
@@ -32,8 +34,9 @@
To ensure type-safety, @SuperBuilder
generates two inner builder classes for each annotated class, one abstract and one concrete class named FoobarBuilder
and FoobarBuilderImpl
(where Foobar is the name of the annotated class).
- Customizing the code generated by @SuperBuilder
is limited to adding new methods or annotations to the builder classes, and providing custom implementations of the 'set', builder()
, and build()
methods.
- You have to make sure that the builder class declaration headers match those that would have been generated by lombok. Due to the heavy generics usage, we strongly advice to copy the builder class definition header from the uncustomized delomboked code.
+ You can customize most of the code generated by @SuperBuilder
, except for internal methods (e.g. self()
).
+ You have to make sure that the builder class declaration headers match those that would have been generated by lombok.
+ Due to the heavy generics usage, we strongly advice to take the uncustomized delomboked code as a reference when customizing @SuperBuilder
.
The configurable aspects of builder are: