我构建了一个包含如下对象的对象:
public class TestThis implements Listener{
private EventsManager eventsManager;
private ConfigManager configManager;
public TestThis() {
eventsManager = new EventsManager();
eventsManager.addListener(this);
configManager = new ConfigManager(this);
}
public ConfigManager getConfigManager() {
return configManager;
}
@Override
public void configLoadedSuccessfully(Event event) {
System.out.println(this.configManager); //OUTPUT NULL
System.out.println(this.getConfigManager());//OUTPUT NULL
}
}
configManager
对象存在问题。
在构造中,一切正常,但configLoadedSuccessfully
是事件,configManager
为null,其evrywhere为null。
侦听器代码:
public interface Listener{
public void configLoadedSuccessfully(Event event);
}
答案 0 :(得分:1)
我添加了一个函数,该函数开始加载配置并更改var的创建顺序。
public class TestThis implements Listener{
private EventsManager eventsManager;
private ConfigManager configManager;
public TestThis() {
eventsManager = new EventsManager();
configManager = new ConfigManager(this);
eventsManager.addListener(this);
configManager.load();
}
public ConfigManager getConfigManager() {
return configManager;
}
@Override
public void configLoadedSuccessfully(Event event) {
System.out.println(this.configManager);
System.out.println(this.getConfigManager());
}
}