title: Serialization of static fields with readResolve()
body: <p>When I serialize an object I want to also take a "snapshot" of the static fields.
  Is the following code a good practice ?</p>
  
  <pre><code>public class ClassA implements Serializable {
  
      private int num1;
      private static int num2 = 5;
  
      private int num2Saver;
  
      public int getNum1() {
          return num1;
      }
  
      public void setNum1(int num1) {
          this.num1 = num1;
      }
  
      public static int getNum2() {
          return num2;
      }
  
      public void setNum2(int num2) {
          ClassA.num2 = num2;
          num2Saver = num2;
      }
  
      private Object readResolve(){
          num2 = num2Saver;
          return this;
      }
  }
  </code></pre>
  
  <p>(notice that in order to set the static field you have to go through an instance )</p>