Most of my experience with Java has been in the classroom setting, editing my own code. I'm finally venturing into the exciting world of deciphering other people's code, and I'm wondering about this:
public class MyClass {
// Some fields here
// A constructor there
// Setters and getters abound
public static MyClass create() {
return new MyClass();
}
}
I'm wondering what the purpose of this method is. It doesn't seem like more trouble to write MyClass foo = new MyClass();
than to write MyClass foo = MyClass.create();
. Is this some kind of Java idiom I'm unaware of? Is it completely unnecessary? Would it perhaps be somehow more useful in a class where the constructor took any parameters? What's the deal?
Thanks!