Difference between calling new and getInstance()

前端 未结 6 1828
一个人的身影
一个人的身影 2021-01-31 11:30

Is calling Class.getInstance() equivalent to new Class()? I know the constructor is called for the latter, but what about getInstance()? T

6条回答
  •  后悔当初
    2021-01-31 12:27

    In the context of an abstract class, a getInstance() method may represent the factory method pattern. An example is the abstract Calendar class, which includes static factory methods and a concrete subclass.

提交回复
热议问题