Hi, what is a correct (and simple) way to create an singleton?

This is how I see that now:

```
class ApMessageRouter
{
        
        static ApMessageRouter instance = null;
        
        
private this() { } // for disable constructor to use from outside
        
        
        public ApMessageRouter getInstance()
        {
                if (this.instance is null) {
                        this.instance = new ApMessageRouter();
                }
                return this.instance;
        }
        
}
```

Thank you.

Reply via email to