From a2445096cb24fef823a54e34f1e6684b485fc112 Mon Sep 17 00:00:00 2001
From: daliclass
In practice, @Value
is shorthand for: final @ToString @EqualsAndHashCode @AllArgsConstructor @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @Getter
, except that explicitly including an implementation of any of the relevant methods simply means that part won't be generated and no warning will be emitted. For example, if you write your own toString
, no error occurs, and lombok will not generate a toString
. Also, any explicit constructor, no matter the arguments list, implies lombok will not generate a constructor. If you do want lombok to generate the all-args constructor, add @AllArgsConstructor
to the class. You can mark any constructor or method with @lombok.experimental.Tolerate
to hide them from lombok.
- It is possible to override the final-by-default and private-by-default behavior using either an explicit access level on a field, or by using the @NonFinal
or @PackagePrivate
annotations.
+ It is possible to override the final-by-default and private-by-default behavior using either an explicit access level on a field, or by using the @NonFinal
or @PackagePrivate
annotations. @NonFinal
can also be used on a class to remove the final keyword.
It is possible to override any default behavior for any of the 'parts' that make up @Value
by explicitly using that annotation.
true
, generated setters and getters will simply be named the same as the field name, without a get
or set
prefix.
llombok.anyConstructor.addConstructorProperties
+ lombok.anyConstructor.addConstructorProperties
true
, lombok will generate a @java.beans.ConstructorProperties
annotation when generating constructors. This is particularly useful for GWT and Android development. Note that you'll need to depend on module 'java.desktop' if you're using jigsaw.
+ If true
, lombok will generate a @java.beans.ConstructorProperties
annotation when generating constructors. Note that you'll need to depend on module 'java.desktop' if you're using jigsaw.
lombok.log.fieldName
@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.
+
+ @Builder(access = AccessLevel.PACKAGE)
is legal (and will generate the builder class, the builder method, etc with the indicated access level) starting with lombok v1.18.8.
"builder"
)
toBuilder()
(default: no)
+ public
).
@Builder(builderClassName = "HelloWorldBuilder", buildMethodName = "execute", builderMethodName = "helloWorld", toBuilder = true)
@Builder(builderClassName = "HelloWorldBuilder", buildMethodName = "execute", builderMethodName = "helloWorld", toBuilder = true, access = AccessLevel.PRIVATE)
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.
+
+ If setting the access level to PROTECTED
, all methods generated inside the builder class are actually generated as public
; the meaning of the
+ protected
keyword is different inside the inner class, and the precise behaviour that PROTECTED
would indicate (access by any source in the same package is allowed, as well as any subclasses from the outer class, marked with @Builder
is not possible, and marking the inner members public
is as close as we can get.
@FieldNameConstants was redesigned in lombok v1.18.4. +
+ The lombok.config option lombok.fieldNameConstants.uppercase = true
was added in lombok v1.18.8.
- The @FieldNameConstants
annotation generates an inner type which contains 1 constant for each field in your class; either string constants (fields marked public static final
, of type java.lang.String
) or if you prefer, an enum type with 1 value for each field - write @FieldNameConstants(asEnum = true)
for the enum variant. @FieldNameConstants
is useful for various marshalling and serialization frameworks. The constant field (whether enum value or string constant) always has the exact same name as the field, capitalization and all.
+ The @FieldNameConstants
annotation generates an inner type which contains 1 constant for each field in your class; either string constants (fields marked public static final
, of type java.lang.String
) or if you prefer, an enum type with 1 value for each field - write @FieldNameConstants(asEnum = true)
for the enum variant. @FieldNameConstants
is useful for various marshalling and serialization frameworks. The constant field (whether enum value or string constant) always has the exact same name as the field, capitalization and all, unless you set the lombok.fieldNameConstants.uppercase = true
option in your lombok.config
file; in that case lombok will try to UPPER_CASE
the name.
The generated inner type is by default called Fields
and is public
. You can modify this via @FieldNameConstants(innerTypeName = "FieldNames", access = AccessLevel.PACKAGE)
for example. The default inner type name can also be modified via configuration key lombok.fieldNameConstants.innerTypeName
. The generated fields are always public
.
@@ -39,6 +41,10 @@
lombok.fieldNameConstants.innerTypeName
= a string (default: 'Fields')
lombok.fieldNameConstants.uppercase
= [true
| false
] (default: false)
+ true
, attempt to uppercase the generated fields.