2
    //Singleton
    public class MainList implements Serializable {
            private static MainList instance = new MainList();
            private MainList() {}

            public static MainList getInstance() {
                return instance;
            }
        }

    //Trying to deserialize..
    public MainWindow() {
        //Importing the latest version if it exists in path
        MainList mainListObj = MainList.getInstance();
        try {
            FileInputStream fis = new FileInputStream(path);
            ObjectInputStream oin = new ObjectInputStream(fis);
            mainListObj = (MainList) oin.readObject(); //HERE//////
        }
        catch (Exception exc) {
            return;
        }
    }

Singleton-Object of class MainList is serialized & can be found by path.

On the line //HERE/// object successfully deserializing to mainListObj, BUT it's local..

How can I make it global? I think it could be solved by chanching getInstance method..somehow..

Nick Kulese
  • 83
  • 1
  • 2
  • 12

1 Answers1

0

Your case is not singleton.

In your case, you can simply provide a setter.

static void setInstance(MainList newInstance) {
 instance = newInstance;
}

MainList.setInstance(mainListObj);
Dean Xu
  • 4,438
  • 1
  • 17
  • 44