Created
June 1, 2017 05:41
-
-
Save ToniYang/ab5b483b48342b99520c523cb22feb41 to your computer and use it in GitHub Desktop.
java的创建单例的正确方式
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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