This is the non-lazy method of implementing the Singleton pattern for languages that support it. It’s perfectly acceptable to do this, especially since it’s one of the ways of implementing a thread-safe Singleton. However, if your Singleton object is expensive (see lazy initialization) to create, then it might not be appropriate to create it in this manner.
If your code doesn’t compile, as the other answers point out, your syntax for the doSomething
method is incorrect.
solved Initializing singleton in class instead of instance? [closed]