Is calling Class.getInstance()
equivalent to new Class()
?
I know the constructor is called for the latter, but what about getInstance()
?
T
Absolutely (usually) not.
getInstance
is the static method often used with the Singleton Pattern in Java. The new
keyword actually creates a new object. At some point there must be a new
(although there are a few other methods to instantiate new objects) to actually create the object that getInstance
returns.