Is calling Class.getInstance()
equivalent to new Class()
?
I know the constructor is called for the latter, but what about getInstance()
?
T
For start:
newInstance()
is a static method
. This means you can access to it without creating new class directly! And it creates that class itself "with necessary inits" (via an inner new myClass()
). This means you can add some newInstance
methods (newInstance4usage1, newInstance4usage2,...) for different needs that per static method creates class with different initialization.
Sometimes, this helps class's user (final programmer) to creating class without any worry and very comfortable.
This helps really when the init process is complex or has important or or usual levels. this method don't prevent from creating class by new
keyword.
I like it!
Excuse me for slow answering, I am typing with my mobile phone!