title: Java static variable for auto-increment (userID) ObjectOutputStream
body: <p>I have this assignment at school. It includes making a "Person" class, and put each object in a list. Each Person object should have a unique ID. This is achieved by defining a static int in the class, like this: </p>
  
  <pre><code>public class MyClass implements Serializable
  {
    private static int nextmember;
    private int userid;
  
    public MyClass()
    {
      userid = nextmember++;
    }
  }
  </code></pre>
  
  <p>This works well enough, first object gets userid 1, next object userid 2 etc. My challenge is how to deal with this when also saving to file? I use ObjectOutputStream and ObjectInputStream. </p>
  
  <p>So if I create 3 objects, 1, 2 and 3, close my program (everything is saved to file), re-open the program (all 3 objects are present), and create a fourth object, the fourth object is given userid 1. How can I preserve the nextmember value through closing / re-opening the program?</p>
  
  <p>Tried googling for it, but all I could find on the subject is that "it doesn't make sense to serialize static variables", so maybe I should find a different approach to userid management?</p>
  
  <p>Thanks,<br>
  Erik</p>