Last active
November 9, 2018 01:22
-
-
Save xuanyu-h/9349aff93d1c013235e2d236d6c69f01 to your computer and use it in GitHub Desktop.
Java Singleton
This file contains hidden or 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 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