About Effective Java item 1.

A disadvantage of static factories is that you can't create subclasses of classes that don't have public or protected constructors.

In other words, I think you can't create a subclass of a class that has a private, package private constructor, but

Is this a drawback of the static factory?

Private, I think that package private constructor subclasses cannot be created in the first place (package private can be a subclass if they are the same package).

Is this not limited to the static factory? I wonder if there are any reasons listed here.

  • Answer # 1

    Effective Java 3rd Edition is written as follows. It seems that the disadvantage in the 2nd Edition has been changed to the restriction (restriction) in the 3rd Edition ("only" has disappeared from the translation).


    The main limitation of providing only static factory methods is that classes without public or protected constructors cannot be subclassed.

    Restrictby providing only static factory methods, not "disadvantages of static factory methods". Immediately after it is written, "It's okay in fact," is not a fault.