Eine Möglichkeit Singletons in Java zu implementieren ist die folgende:
public class MySingleton {
private static final MySingleton INSTANCE = new MySingleton();
private MySingleton() {
}
public static MySingleton getInstance() {
return INSTANCE;
}
}
Diese Implementierung hat die schöne Eigenschaft, dass die Instanz von MySingleton erst in dem Moment erstellt wird, in dem sie zum ersten Mal benötigt wird. Die JVM erlaubt uns hier also Lazy-Loading.