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

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -