In my opinion, if you are not doing lazy-loading (which you are not in this case), getters should not change the value. Therefore, I would:
Put the change in the installer
public void setMyValue(String value) { if(value == null || value.isEmpty()){ this.myValue = "N/A"; } else { this.myValue = value; } }
Or make getter return the default value if the value is not set properly:
public String getMyValue() { if(this.myvalue == null || this.myvalue.isEmpty()){ return "N/A"; } return this.myValue; }
In the case of lazy loading, where I would say that changing your members in getter is ok, you would do something like:
public String getMyValue() { if (this.myvalue == null) { this.myvalue = loadMyValue(); } return this.myValue; }
Vincent Mimoun-Prat Dec 14 '12 at 9:50 2012-12-14 09:50
source share