Skip to content

Instantly share code, notes, and snippets.

@xuanyu-h
Last active November 9, 2018 01:22
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 xuanyu-h/9349aff93d1c013235e2d236d6c69f01 to your computer and use it in GitHub Desktop.
Save xuanyu-h/9349aff93d1c013235e2d236d6c69f01 to your computer and use it in GitHub Desktop.
Java Singleton
// 定义单例模式中需要完成的代码逻辑
public interface MySingleton {
void doSomething();
}
public enum Singleton implements MySingleton {
INSTANCE {
@Override
public void doSomething() {
System.out.println("complete singleton");
}
};
public static MySingleton getInstance() {
return Singleton.INSTANCE;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment