Singleton: Difference between revisions

Line 776:
 
// Any other methods
}</lang>
 
===Thread-Safe Lazy-Loaded===
This is the [[wp:Initialization-on-demand holder idiom]].
<lang java>public class Singleton {
private Singleton() {
// Constructor code goes here.
}
 
private static class LazyHolder {
private static final Singleton INSTANCE = new Singleton();
}
 
public static Singleton getInstance() {
return LazyHolder.INSTANCE;
}
}</lang>
 
Anonymous user