Im looking to easy way to set many parameters to object and return object itself. So I can set any object. something like:
public class Foo {
private int mValue1;
private String mValue2;
private boolean mValue3;
private long mValue4;
public Foo() {
}
public Foo setValue1(int value1) {
mValue1 = value1;
return this;
}
public Foo setValue2(String value2) {
mValue2 = value2;
return this;
}
public Foo setValue3(boolean value3) {
mValue3 = value3;
return this;
}
public Foo setValue4(long value4) {
mValue4 = value4;
return this;
}
}
I am looking for an auto-generate tool which helps me to achieve that.
Having them(members) in constructor enforcing me to set null for all members. Also having over-loading constructors are headache when update members.
I think I found the answer .. There is a shipped template called Builder
with Android Studio (Intellij-Idea) does that job smoothly.
Builder
template from Template menuEven more you can customise the setter template 🙂
Good luck,'.
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