Skip to content

Commit 13abf49

Browse files
author
yejinchang
committed
enum approach of singleton
1 parent 13e6c74 commit 13abf49

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

singleton/src/main/java/com/iluwatar/App.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,9 @@ public static void main(String[] args) {
2222
System.out.println("threadSafeIvoryTower1=" + threadSafeIvoryTower1);
2323
System.out.println("threadSafeIvoryTower2=" + threadSafeIvoryTower2);
2424

25+
EnumIvoryTower enumIvoryTower1 = EnumIvoryTower.getInstance();
26+
EnumIvoryTower enumIvoryTower2 = EnumIvoryTower.getInstance();
27+
System.out.println("enumIvoryTower1=" + enumIvoryTower1.getDeclaringClass().getCanonicalName() + "@" + enumIvoryTower1.hashCode());
28+
System.out.println("enumIvoryTower2=" + enumIvoryTower2.getDeclaringClass().getCanonicalName() + "@" + enumIvoryTower2.hashCode());
2529
}
2630
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.iluwatar;
2+
3+
/**
4+
*
5+
* Enum Singleton class.
6+
*
7+
*/
8+
public enum EnumIvoryTower {
9+
INSTANCE;
10+
11+
public static EnumIvoryTower getInstance() {
12+
return INSTANCE;
13+
}
14+
}

0 commit comments

Comments
 (0)