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.
There doesn't seem to be anything stopping me from instantiating the elements directly, e.g.
MyElement element = new MyElement();
whereas tutorials seem to prefer
MyElement element = new ObjectFactory().createMyElement();
If I look into ObjectFactory.java, I see:
public MyElement createMyElement() {
return new MyElement();
}
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.