<#import "../_features.html" as f> <@f.scaffold title="@Accessors" logline="A more fluent API for getters and setters."> <@f.history>

@Accessors was introduced as experimental feature in lombok v0.11.0.

The lombok.config option lombok.accessors.capitalization = [basic | beanspec] was added in lombok v1.18.24.

<@f.experimental> Current status: neutral - Some changes are expected. These changes are intended to be backwards compatible, but should start in an experimental feature: <@f.overview>

The @Accessors annotation is used to configure how lombok generates and looks for getters and setters.

By default, lombok follows the bean specification for getters and setters: The getter for a field named pepper is getPepper for example. However, some might like to break with the bean specification in order to end up with nicer looking APIs. @Accessors lets you do this.

Some programmers like to use a prefix for their fields, i.e. they write fPepper instead of pepper. We strongly discourage doing this, as you can't unit test the validity of your prefixes, and refactor scripts may turn fields into local variables or method names. Furthermore, your tools (such as your editor) can take care of rendering the identifier in a certain way if you want this information to be instantly visible. Nevertheless, you can list the prefixes that your project uses via @Accessors as well.

@Accessors therefore has 3 options:

The @Accessors annotation is legal on types and fields; the annotation that applies is the one on the field if present, otherwise the one on the class. When an @Accessors annotation on a field is present, any @Accessors annotation also present on the class the field is in, is entirely ignored, even for properties not configured on the field @Accessors. This in contrast to any lombok.config configuration keys which serve as fall-back default if any explicit @Accessors annotation doesn't specify.

<@f.snippets name="experimental/Accessors" /> <@f.confKeys>
lombok.accessors.chain = [true | false] (default: false)
If set to true, any class that either doesn't have an @Accessors annotation, or it does, but that annotation does not have an explicit value for the chain parameter, will act as if @Accessors(chain = true) is present.
lombok.accessors.fluent = [true | false] (default: false)
If set to true, any class that either doesn't have an @Accessors annotation, or it does, but that annotation does not have an explicit value for the fluent parameter, will act as if @Accessors(fluent = true) is present.
lombok.accessors.prefix += a field prefix (default: empty list)
This is a list property; entries can be added with the += operator. Inherited prefixes from parent config files can be removed with the -= operator. Any class that either doesn't have an @Accessors annotation, or it does, but that annotation does not have an explicit value for the prefix parameter, will act as if @Accessors(prefix = {prefixes listed in configuration}) is present.
lombok.accessors.capitalization = [basic | beanspec] (default: basic)
Controls how tricky cases like uShaped (one lowercase letter followed by an upper/titlecase letter) are capitalized. basic capitalizes that to getUShaped, and beanspec capitalizes that to getuShaped instead.
Both strategies are commonly used in the java ecosystem, though beanspec is more common.
lombok.accessors.flagUsage = [warning | error] (default: not set)
Lombok will flag any usage of @Accessors as a warning or error if configured.
<@f.smallPrint>

The nearest @Accessors annotation is also used for the various methods in lombok that look for getters, such as @EqualsAndHashCode.

If a prefix list is provided and a field does not start with one of them, that field is skipped entirely by lombok, and a warning will be generated.