/ Published in: Java
Classe Singleton
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
public class Singleton { private static Singleton istance = null; // riferimento all'istanza private Singleton() { } // costruttore public static Singleton getIstance() { if(istance==null) synchronized(Singleton.class) { if(instance == null) istance = new Singleton(); } return istance; } public void metodo() { ... } .... } ... Singleton sg1 = Singleton.getIstance(); // Crea l'istanza sg1.metodo(); ...