What is the purpose of getInstance()
in Java?
During my research I keep reading that getInstance()
helps achieve a Singleton design pattern (w
I prefer to use static
too, but sometimes getInstance()
is helpful to have some functions that will be related to the object, in which you can modify variables. if you are simply making some util functions that do not need an instance of an object, use static
.
When you are using someone's libraries, you never know if a function body needs a class instance. That's why a lot of library classes are using getInstance()
.