GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||
GeezerVison is showing projectlombok.org — @Getter and @Setter
Get Lombok for Enterprise
@Getter and @SetterNever write
|
import lombok.AccessLevel;
|
public class GetterSetterExample {
|
lombok.accessors.chain = [true | false] (default: false)
true, generated setters will return this (instead of void). An explicitly configured chain parameter of an @Accessors annotation takes precedence over this setting.
lombok.accessors.fluent = [true | false] (default: false)
true, generated getters and setters will not be prefixed with the bean-standard 'get, is or set; instead, the methods will use the same name as the field (minus prefixes). An explicitly configured fluent parameter of an @Accessors annotation takes precedence over this setting.
lombok.accessors.prefix += a field prefix (default: empty list)
+= operator. Inherited prefixes from parent config files can be removed with the -= operator. Lombok will strip any matching field prefix from the name of a field in order to determine the name of the getter/setter to generate. For example, if m is one of the prefixes listed in this setting, then a field named mFoobar will result in a getter named getFoobar(), not getMFoobar(). An explicitly configured prefix parameter of an @Accessors annotation takes precedence over this setting.
lombok.getter.noIsPrefix = [true | false] (default: false)
true, getters generated for boolean fields will use the get prefix instead of the defaultis prefix, and any generated code that calls getters, such as @ToString, will also use get instead of is
lombok.accessors.capitalization = [basic | beanspec] (default: basic)
uShaped (one lowercase letter followed by an upper/titlecase letter) are capitalized. basic capitalizes that to getUShaped, and beanspec capitalizes that to getuShaped instead.beanspec is more common.
lombok.setter.flagUsage = [warning | error] (default: not set)
@Setter as a warning or error if configured.
lombok.getter.flagUsage = [warning | error] (default: not set)
@Getter as a warning or error if configured.
lombok.copyableAnnotations = [A list of fully qualified types] (default: empty list)
For generating the method names, the first character of the field, if it is a lowercase character, is title-cased, otherwise, it is left unmodified. Then, get/set/is is prefixed.
No method is generated if any method already exists with the same name (case insensitive) and same parameter count. For example, getFoo() will not be generated if there's already a method getFoo(String... x) even though it is technically possible to make the method. This caveat exists to prevent confusion. If the generation of a method is skipped for this reason, a warning is emitted instead. Varargs count as 0 to N parameters. You can mark any method with @lombok.experimental.Tolerate to hide them from lombok.
For boolean fields that start with is immediately followed by a title-case letter, nothing is prefixed to generate the getter name.
Any variation on boolean will not result in using the is prefix instead of the get prefix; for example, returning java.lang.Boolean results in a get prefix, not an is prefix.
A number of annotations from popular libraries that indicate non-nullness, such as javax.annotation.Nonnull, if present on the field, result in an explicit null check in the generated setter.
Various well-known annotations about nullability, such as org.eclipse.jdt.annotation.NonNull, are automatically copied over to the right place (method for getters, parameter for setters). You can specify additional annotations that should always be copied via lombok configuration key lombok.copyableAnnotations.
You can annotate a class with a @Getter or @Setter annotation. Doing so is equivalent to annotating all non-static fields in that class with that annotation. @Getter/@Setter annotations on fields take precedence over the ones on classes.
Using the AccessLevel.NONE access level simply generates nothing. It's useful only in combination with @Data or a class-wide @Getter or @Setter.
@Getter can also be used on enums. @Setter can't, not for a technical reason, but for a pragmatic one: Setters on enums are an extremely bad idea.