title: Deserializing (loading) into an existing object
body: <p>I have a class <code>Foo</code> in which reside these 2 methods:</p>
  
  <pre><code>save() and load()
  
  void save() { ... }
  
  static final Foo load() { ... }
  </code></pre>
  
  <p>The purpose of these methods are to save and load Foo objects via Java Serialization</p>
  
  <p>However, I've realized now that they are fundamentally flawed for what I need to do - namely because in order to load data, I must create a brand-spanking new object of class Foo.</p>
  
  <p>What I need to do instead is to call load from within Foo sometimes... to be able to deserialize straight into the existing Foo object (replacing the existing data present)</p>
  
  <p>How can I do this?</p>
  
  <p>All I can think of is to move all the fields that exist in Foo into an inner class</p>
  
  <pre><code>class Foo {
      String field1;
      int field2;
  }
  
  new way:
  
  class Foo {
      class Bar {
          String field1;
          int field2;
      }
      Bar data;
  
      void load() { data = deserlializeBar(); }
  }
  </code></pre>
  
  <p>are there any simpler ways?</p>