mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-10-14 00:16:48 +00:00
enum approach of singleton
This commit is contained in:
1 parent
13e6c74d97
commit
13abf49024
2 files changed
+18
No files matched your search
@@ -22,5 +22,9 @@ public class App {
|
|||||||
System.out.println("threadSafeIvoryTower1=" + threadSafeIvoryTower1);
|
System.out.println("threadSafeIvoryTower1=" + threadSafeIvoryTower1);
|
||||||
System.out.println("threadSafeIvoryTower2=" + threadSafeIvoryTower2);
|
System.out.println("threadSafeIvoryTower2=" + threadSafeIvoryTower2);
|
||||||
|
|
||||||
|
EnumIvoryTower enumIvoryTower1 = EnumIvoryTower.getInstance();
|
||||||
|
EnumIvoryTower enumIvoryTower2 = EnumIvoryTower.getInstance();
|
||||||
|
System.out.println("enumIvoryTower1=" + enumIvoryTower1.getDeclaringClass().getCanonicalName() + "@" + enumIvoryTower1.hashCode());
|
||||||
|
System.out.println("enumIvoryTower2=" + enumIvoryTower2.getDeclaringClass().getCanonicalName() + "@" + enumIvoryTower2.hashCode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.iluwatar;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Enum Singleton class.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public enum EnumIvoryTower {
|
||||||
|
INSTANCE;
|
||||||
|
|
||||||
|
public static EnumIvoryTower getInstance() {
|
||||||
|
return INSTANCE;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user