Java - Design Pattern - Singleton

From My Limbic Wiki
Revision as of 01:04, 1 November 2019 by Fukakai (talk | contribs) (Page créée avec « <source lang="Java"> public class SingletonClass { private static SingletonClass SINGLE_INSTANCE = null; private SingletonClass() {} public static Singleto... »)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

<source lang="Java">

public class SingletonClass {

   private static SingletonClass SINGLE_INSTANCE = null;
   private SingletonClass() {}
   public static SingletonClass getInstance() {
       if (SINGLE_INSTANCE == null) {
           synchronized (SingletonClass.class) {
               if (SINGLE_INSTANCE == null) {
                   SINGLE_INSTANCE = new SingletonClass();
               }
           }
       }
       return SINGLE_INSTANCE;
   }

} </source>