Roedy said:
It is a trap for the unwary. There is no benefit in it. It is
motivated by malicious pranksterism.
1. It is a trap for the unwary. I agree. There are many of these in Java
and elsewhere.
2. The benefit has already been cited, but, to re-iterate, it provides
finer-grained control over *who* may subclass the class. Consider this
form of the abstract factory pattern:
public abstract class AbstractFactory
{
private AbstractFactory() {}
public abstract MyObject createMyObject();
public static createFactory() { return new ConcreteFactory(); }
static class ConcreteFactory extends AbstractFactory
{
public Object createMyObject() { return new MyObject(); }
}
}
You might describe the ability to write that as a marginal or dubious
benefit, but it is certainly not 'no benefit'. Consider also the case
where the constructors in question are protected or package-private.
3. You can ignore evidence all you want, but when you are reduced to
speculating on motives (whose?) you are getting pretty ridiculous.