I'm using google Auto-value for my objects and also I used Builder
class and create
method to initialize my object, so how can I edit specific parameter of my object without initializing it again?
@AutoValue
public abstract class test implements Parcelable {
public abstract String name();
public abstract int age();
public static test create(String name, int age) {
return builder()
.name(name)
.age(age)
.build();
}
public static Builder builder() {
return new AutoValue_test.Builder();
}
@AutoValue.Builder
public abstract static class Builder {
public abstract Builder name(String name);
public abstract Builder age(int age);
public abstract test build();
}
}
Now in my code I want change the name
property (t contains data):
test t = test.Builder.name("Ali").age(26).build();
/*how to change name value*/
Without initializing it again, you CAN NOT edit specific parameter of your object with @AutoValue
annotation (value-typed object); this immutability is what AutoValue aims to provide for your object, because the main purpose of AutoValue is to create immutable objects without writing boilerplate codes.
If you want to know more about AutoValue and what this library aims to achieve the below links may be helpful:
Also, if you want to initialize new object with different parameter value(s), the with-er library may be useful.
I hope it helps.