Skip to content

Instantly share code, notes, and snippets.

@CN6033
Last active August 31, 2015 14:47
Show Gist options
  • Save CN6033/25e163f2b51a06f39262 to your computer and use it in GitHub Desktop.
Save CN6033/25e163f2b51a06f39262 to your computer and use it in GitHub Desktop.
public class SingletonExample {
// Inner class not loaded until some thread reference one of its fileds or methods
private static final class InnerSingleton {
private static final SingletonExample s = new SingletonExample();
}
public static SingletonExample getInstance() {
return InnerSingleton.s;
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment