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 - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -