How to make protective copies of a Mutable object that contains a mutable field in an immutable object?
class ImmutableObject {
private final MutableObject immutable_field;
ImmutableObject(MutableObject y) {
this.immutable_field = y;
}
}
class MutableObject {
public int mutable_field;
}
- There is no constructor in MutableObject that allows me to set a field.
- The current state of a MutableObject must be fixed in an immutable object and never change.
source
share