我有一个最终变量 ,save
它是一些信息的可序列化类。我试图做的是将最终变量设置为该可序列化类,但是我得到了一些相互冲突的警告。我正在尝试这样做,以便如果文件不可加载/不存在,它将简单地创建一个新实例,否则它将使用旧实例。
我的问题在构造函数打开、关闭和从 ObjectInputStream 读取对象时的代码中进行了注释
private final CannonSet save;
public CannonManager(ManCannon plugin) { // Warning that save is not initialized
if (/* some conditional statement */) {
//lot of code removed, unnecessary to problem
//essentially, save was set conditionally here (loaded from file)
this.save = new CannonSet();
}
if (this.save == null) {
this.save = new CannonSet(); // Warning that save may have already been set
}
}