I have a class for all static members. The number of static members is more than 10 (which may increase with time).
I am using lombok and I want to generate Getters/Setters for all static members using single @Getter
and @Setter
annotation on class like we do for non-static members.
I know that
You can also put a @Getter and/or @Setter annotation on a class. In that case, it's as if you annotate all the non-static fields in that class with the annotation.
I also know that
We can annotate static fields individually using
@Getter @Setter
to generate Getters/Setters for static fields.
But this looks ugly and I want to make my class look as clean as possible.
Is there any way I can configure / Override @Getter and @Setter annotation so that I can annotate the class and it generate Getters and Setters for all members including static and non-static members, after all what those methods do is to return the mentioned variable.
To be more precise, i want following code snippet to generate Getters and Setters for all class variables-
@Getter
@Setter
public class myClass {
private static String d;
private static SomePojo c;
private String a;
private Integer b;
private SomeClass d;
}
Yes, getters/setters can be made static based on your need.
Overview. You can annotate any field with @Getter and/or @Setter , to let lombok generate the default getter/setter automatically. A default getter simply returns the field, and is named getFoo if the field is called foo (or isFoo if the field's type is boolean ).
The @With relies on a constructor for all fields in order to do its work. If this constructor does not exist, your @With annotation will result in a compile time error message. You can use Lombok's own @AllArgsConstructor , or as Value will automatically produce an all args constructor as well, you can use that too.
Add @Getter
to the static member itself and it should work.
@Getter
private static final String DEFAULT_VAL = "TEST";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With