From 19ad4fd57d32afad1a33f20613fbb2e7607cfee0 Mon Sep 17 00:00:00 2001
From: Reinier Zwitserloot
- @SuperBuilder
was introduced as experimental feature in lombok v1.18.1.
+ @SuperBuilder
was introduced as experimental feature in lombok v1.18.2.
@SuperBuilder
can generate so-called 'singular' methods for collection parameters/fields. For details, see the @Singular
documentation in @Builder
.
- As lombok has no access to the fields of superclasses when generating the builder code, the methods for setting those superclass fields can only be in the builder of the superclass.
- Therefore, a @SuperBuilder
must extend the @SuperBuilder
of the superclass in order to include those methods.
- Furthermore, the generated builder code heavily relies on generics to avoid class casting when using the builder.
- @SuperBuilder
generates a private constructor on the class that takes a builder instances as a parameter. This constructor sets the fields of the new instance to the values from the 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
is not compatible with @Builder
.
@@ -41,8 +38,6 @@
@f.overview> - <@f.snippets name="Builder" /> - <@f.confKeys>lombok.superBuilder.flagUsage
= [warning
| error
] (default: not set)
@@ -66,6 +61,8 @@
The sorted collections (java.util: SortedSet
, NavigableSet
, SortedMap
, NavigableMap
and guava: ImmutableSortedSet
, ImmutableSortedMap
) require that the type argument of the collection has natural order (implements java.util.Comparable
). There is no way to pass an explicit Comparator
to use in the builder.
An ArrayList
is used to store added elements as call methods of a @Singular
marked field, if the target collection is from the java.util
package, even if the collection is a set or map. Because lombok ensures that generated collections are compacted, a new backing instance of a set or map must be constructed anyway, and storing the data as an ArrayList
during the build process is more efficient that storing it as a map or set. This behaviour is not externally visible, an implementation detail of the current implementation of the java.util
recipes for @Singular
.
+
+ The generated builder code heavily relies on generics to avoid class casting when using the builder.
@f.smallPrint> @f.scaffold> diff --git a/website/templates/features/experimental/index.html b/website/templates/features/experimental/index.html index 309303a0..988a7154 100644 --- a/website/templates/features/experimental/index.html +++ b/website/templates/features/experimental/index.html @@ -64,7 +64,7 @@ @main.feature> <@main.feature title="@SuperBuilder" href="SuperBuilder"> - Bob now knows his ancestors: Builders with fields from superclasses, too. + Bob now knows his ancestors: Builders with fields from superclasses, too. @main.feature> -- cgit