From 228e99fe5203e92c7297325fec69a82abc1a4bd7 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Mon, 25 Mar 2019 23:11:48 +0100 Subject: [fixes #2046] you can now suppress the builder() method, useful if you only want toBuilder(). Also suppresses the warnings about any missing Builder.Default annotations. --- website/templates/features/Builder.html | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'website') diff --git a/website/templates/features/Builder.html b/website/templates/features/Builder.html index 082b97ed..0818f9d2 100644 --- a/website/templates/features/Builder.html +++ b/website/templates/features/Builder.html @@ -10,6 +10,8 @@ @Builder with @Singular adds a clear method since lombok v1.16.8.

@Builder.Default functionality was added in lombok v1.16.16. +

+ @Builder(builderMethodName = "") is legal (and will suppress generation of the builder method) starting with lombok v1.18.8.

@@ -183,6 +185,13 @@ public class JacksonExample { The initializer on a @Builder.Default field is removed and stored in a static method, in order to guarantee that this initializer won't be executed at all if a value is specified in the build. This does mean the initializer cannot refer to this, super or any non-static member. If lombok generates a constructor for you, it'll also initialize this field with the initializer.

Various well known annotations about nullity cause null checks to be inserted and will be copied to parameter of the builder's 'setter' method. See Getter/Setter documentation's small print for more information. +

+ You can suppress the generation of the builder() method, for example because you just want the toBuilder() functionality, by using: + @Builder(builderMethodName = ""). Any warnings about missing @Builder.Default annotations will disappear when you do this, as such warnings + are not relevant when only using toBuilder() to make builder instances. +

+ You can use @Builder for copy constructors: foo.toBuilder().build() makes a shallow clone. Consider suppressing the generating of the + builder method if you just want this functionality, by using: @Builder(toBuilder = true, builderMethodName = "").

Due to a peculiar way javac processes static imports, trying to do a non-star static import of the static builder() method won't work. Either use a star static import: `import static TypeThatHasABuilder.*;` or don't statically import the builder method.

-- cgit