Skip to content

Instantly share code, notes, and snippets.

@RitterHou
Last active March 7, 2017 08:58
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 RitterHou/02233616db5781d484e0e6e52bf352a5 to your computer and use it in GitHub Desktop.
Save RitterHou/02233616db5781d484e0e6e52bf352a5 to your computer and use it in GitHub Desktop.
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