title: What's the point of JAXB 2's ObjectFactory classes?
body: <p>I'm new to using JAXB, and I used JAXB 2.1.3's xjc to generate a set of classes from my XML Schema. In addition to generating a class for each element in my schema, it created an ObjectFactory class.</p>
  
  <p>There doesn't seem to be anything stopping me from instantiating the elements directly, e.g.</p>
  
  <pre><code>MyElement element = new MyElement();
  </code></pre>
  
  <p>whereas tutorials seem to prefer</p>
  
  <pre><code>MyElement element = new ObjectFactory().createMyElement();
  </code></pre>
  
  <p>If I look into ObjectFactory.java, I see:</p>
  
  <pre><code>public MyElement createMyElement() {
      return new MyElement();
  }
  </code></pre>
  
  <p>so what's the deal? Why should I even bother keeping the ObjectFactory class around? I assume it will also be overwritten if I were to re-compile from an altered schema.</p>