<#import "../_features.html" as f> <@f.scaffold title="@FieldNameConstants" logline="Name... that... field! String constants for your field's names."> <@f.history>

@FieldNameConstants was introduced as experimental feature in lombok v1.16.22.

@FieldNameConstants was redesigned in lombok v1.18.4.

<@f.experimental> Current status: neutral - As a just-introduced feature we're still gathering feedback. <@f.overview>

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. @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 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.

Must be applied to classes (or enums, though you'd rarely want to do that). By default includes all non-transient, non-static fields. You can use @FieldNameConstants.Include in fields + @FieldNameConstants(onlyExplicitlyIncluded = true), or @FieldNameConstants.Exclude for more fine-grained control.

<@f.snippets name="experimental/FieldNameConstants" /> <@f.confKeys>
lombok.fieldNameConstants.flagUsage = [warning | error] (default: not set)
Lombok will flag any usage of @FieldDefaults as a warning or error if configured.
lombok.fieldNameConstants.innerTypeName = a string (default: 'Fields')
The name of the inner type generated by lombok can be controlled with this configuration key.
<@f.smallPrint>

From lombok v1.16.22 to lombok v1.18.2, this feature generated constants inside the type directly; the name of these fields would for example turn field exampleFieldName into public static final String FIELD_EXAMPLE_FIELD_NAME = "exampleFieldName";. The prefix and suffix (here, FIELD_, and the empty string) were configurable. Starting with lombok v1.18.4 this feature has been redesigned into generating an inner type as described above.

Any parameters of lombok annotations that take strings need to be supplied actual string literals; you cannot have references to constants like those generated by @FieldNameConstants. If you'd like to use @FieldNameConstants to for example fill in the of and/or exclude parameters of @ToString and similar lombok annotations, use the @ToString.Include / @ToString.Exclude etc system instead; these are described at the feature pages for those features.

Like other lombok handlers that touch fields, any field whose name starts with a dollar ($) symbol is skipped entirely. Such a field will not be modified at all. Static fields are also skipped.