I tried this.
@lombok.Getter
@lombok.Setter
@lombok.Accessors(chain = true, fluent = true)
private String prop;
And @Accessor
took precedence and getProp
and setProp
are not generated.
How can I make it generate this?
public String getProp() {
return prop;
}
public String prop() {
//return prop;
return getProp(); // wow factor
}
public void setProp(String prop) {
this.prop = prop;
}
public Some prop(String prop) {
//this.prop = prop;
setProp(prop); // wow factor, again
return this;
}
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 @Accessors annotation is used to configure how lombok generates and looks for getters, setters, and with-ers. By default, lombok follows the bean specification for getters and setters: The getter for a field named pepper is getPepper for example.
Project Lombok (from now on, Lombok) is an annotation-based Java library that allows you to reduce boilerplate code. Lombok offers various annotations aimed at replacing Java code that is well known for being boilerplate, repetitive, or tedious to write.
Unfortunately this is impossible. You need to implement own getters and setters, and add @Getter @Setter and @Accessors(fluent = true) annotaions to achieve this.
@Getter
@Setter
@Accessors(fluent = true)
public class SampleClass {
private int id;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
In result you will have class like:
public class SampleClass {
private int id;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int id(){
return id;
}
public SampleClass id(int id){
this.id=id;
return this;
}
}
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