Created
March 27, 2017 05:19
-
-
Save RealDeanZhao/60bef9d33a7b46feae167cbd6726956e to your computer and use it in GitHub Desktop.
a singleton using enum
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 enum Elvis { | |
INSTANCE; | |
public void leaveTheBuilding() { ... } | |
} | |
static void main(){ | |
Elvis.INSTANCE.leaveTheBuilding(); | |
} | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
<< Effective Java >> Item 3.