I need a mutable boolean field in Java (I will return this field via get* method later and it should be possible to modify this field).
Boolean doesn\'t work because
Are you really saying that you want callers to be able to modify the object's boolean value by manipulating what gets returned? So that the object and caller would share a reference to it?
Just so I understand, given:
class OddClass {
private Boolean strangeFlag;
public Object getAttrbiute(String attributeName) {
if (attributeName.equals("strangeflag")) return (Object)strangeFlag;
...
}
}
And then caller does:
Boolean manipulableFlag = (Boolean) myOddClass.getAttrbiute ("strangeflag");
And then later, if caller changes the value of manipulableFlag, you want that change to happen in the OddClass instance, just as though caller had instead used a setAttrbiute method.
Is that what you're asking?
In that case, you'd need a holder class, as suggested by Adam.