Singleton: Difference between revisions
Content added Content deleted
Line 776: | Line 776: | ||
// Any other methods |
// 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> |
}</lang> |
||