Does anyone know any existing support for modifying the individual properties of immutable objects stored in a JavaBean-compatible object?
For a trivial example:
For a given immutable value class and bean object (without worrying about listeners for this):
public class ValueObject {
private final int value;
public ValueObject(int value) {
this.value = value;
}
public ValueObject withValue(int newValue) {
return new ValueObject(value);
}
}
public class Bean {
private ValueObject value;
public ValueObject getValue() {
return value;
}
public ValueObject setValue(ValueObject value) {
this.value = value;
}
}
You can already view the property as bean.value.value.
I am looking to see if there is an existing way of saying bean.value.value = 3and basically has a call equivalent bean.setValue(bean.getValue().withValue(3));.
Note that the actual value object is much more complex.
Thank!
source
share