October 10, 2020

Implement Singleton design Pattern using static class

Using static class to provide singleton feature, allows to lazy instance creation. The instance is not created until you access that static class.

As, the class and instance is static, we have only one instance, and this by java programming language design.

public final class SingletonStaticWay {
     static class Inner {
         private final static SingletonStaticWay instance = new SingletonStaticWay();

     public static SingletonStaticWay instance(){
         return Inner.instance;