I recently ran into an issue with my object initialization.
I have a class (It is set up this way for persistent data storing and loading)
public class Example extends SuperExample{
private String name = "";
public Example(){
super();
}
public String getName(){
return name;
}
@Override
protected void load(){
name = "Example";
}
}
public abstract class SuperExample{
protected abstract void load();
public SuperExample(){
//Do stuff
load();
}
}
The getName()
that is called after the object is initialized is returning ""
and not "Example"
.
Any idea what the root cause of this could be? If I were to set name
in the constructor it works fine. But when it goes through the super
, it errors.
Example e = new Example();
System.out.println(e.getName());