how can i create a new String in a get Method?(Java) -


i have code down below. want if there no other person in row getmother method create new string or person first name "eva" , return this. code doesn't work. "null". how can this? pls help

public person getmother() {      if (mother == null) {        person p = new person("eva");        }        return mother;     } 

you should initialize mother, not p:

public person getmother() {     if (mother == null) {         mother = new person("eva");     }     return mother; } 

Comments

Popular posts from this blog

javascript - ScrollTo Effect (href to div) -

javascript - ng-class not responding to change in model in Angular? -

javascript - document.registerElement extending HTMLInputElement prototype while using custom tag name to avoid implicit browser style -