Last active
March 7, 2017 08:58
-
-
Save RitterHou/02233616db5781d484e0e6e52bf352a5 to your computer and use it in GitHub Desktop.
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 TestSingleton { | |
public static void main(String[] args) { | |
Singleton singleton = Singleton.getInstance(); | |
singleton.name = "张三"; | |
Singleton singleton1 = Singleton.getInstance(); | |
System.out.println(singleton1.name); | |
} | |
} | |
class Singleton { | |
public String name; | |
private static Singleton singleton; | |
public static Singleton getInstance() { | |
if (singleton == null) | |
singleton = new Singleton(); | |
return singleton; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment