Answers for "how to make a class singleton in java"

1

java singleton

public class DB {
    // champs de l'objet

    private DB(){
        // initialisation des champs
    }

    private static final DB INSTANCE = new DB();
    public static DB getInstance(){
        return INSTANCE;
    }
}
Posted by: Guest on December-16-2021
1

java singleton

public final class SomeSingleton {
   public static final SomeSingleton INSTANCE;

   private SomeSingleton() {
      INSTANCE = (SomeSingleton)this;
      System.out.println("init complete");
   }

   static {
      new SomeSingleton();
   }
}
Posted by: Guest on April-21-2021

Code answers related to "how to make a class singleton in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language