Vanilla Java
01 public enum SingletonEnumExample {
02 INSTANCE;
03
04 public static SingletonEnumExample getInstance() {
05 return INSTANCE;
06 }
07
08 private String s;
09
10 public void bar() {
11 }
12 }
13
14 public class SingletonHolderExample {
15
16 private static class SingletonHolderExampleHolder {
17 private static final SingletonHolderExample INSTANCE = new SingletonHolderExample();
18 }
19
20 public static SingletonHolderExample getInstance() {
21 return SingletonHolderExampleHolder.INSTANCE;
22 }
23
24 private String s;
25
26 public void foo() {
27 }
28 }