+1 to reply to Peter.
Another reason for using factory methods is that they act as "named constructors".
For example, LocalDate has 6 static factory methods (at least I can't be exhaustive here):
of(int year, int/Month month, int dayOfMonth) (two overloads)ofEpochDay(long epochDay)ofYearDay(int year, int dayOfYear)parse(CharSequence text)parse(CharSequence text, DateTimeFormatter formatter)
I think itβs much clearer to understand the values ββof various parameters, using them as separately named methods, rather than a bunch of constructors with very similar types of parameters; you can pretty much guess what the parameters should be for factory methods, while you might have to read Javadoc (shock horror) if they were "unnamed" constructors.
Admittedly, of is the least understood of these names - ofYearMonthDayOfMonth may be required - however, I suspect this is the most commonly used factory method and it is too cluttered to enter this long name all the time.
If you have not read it, step 1 of Effective Java 2nd Edition is all about why and when you need statically static factory methods on constructors. The "named constructor" benefit that I mention here is actually the first benefit of Bloch.
source share