#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 v2.0.0.
@f.history> <@f.experimental>
The @FieldNameConstants
annotation generates string constants (fields marked public static final
, of type java.lang.String
) containing the field's name, as a string. This is useful for various marshalling and serialization frameworks. The constant field has the same as the field it represents, except with all uppercase letters, with underscores in front of the uppercase letters in the original field. If this results in the exact same name, the constant is not generated (a warning is generated instead).
The public
access modifier can be changed via the parameter level = AccessLevel.PACKAGE
for example. You can force a field to be skipped by supplying level = AccessLevel.NONE
.
Can be applied to classes (in which case every field gets a constant), or to an individual field.
@f.overview> <@f.snippets name="experimental/FieldNameConstants" /> <@f.confKeys>lombok.fieldNameConstants.flagUsage
= [warning
| error
] (default: not set)
@FieldDefaults
as a warning or error if configured.
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.