Skip to content

Instantly share code, notes, and snippets.

@ToniYang
Created June 1, 2017 05:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ToniYang/ab5b483b48342b99520c523cb22feb41 to your computer and use it in GitHub Desktop.
Save ToniYang/ab5b483b48342b99520c523cb22feb41 to your computer and use it in GitHub Desktop.
java的创建单例的正确方式
public class Singleton {
private static class SingletonHolder {
public static Singleton resource = new Singleton();
}
public static Singleton getResource() {
return SingletonHolder.resource ;
}
private Singleton(){
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment