Adding initialization on demand holder idiom.
This commit is contained in:
parent
c94c8a3e74
commit
20b1c2bd49
@ -27,22 +27,24 @@ package com.iluwatar.singleton;
|
||||
*/
|
||||
public final class IvoryTower {
|
||||
|
||||
/**
|
||||
* Static to class instance of the class.
|
||||
*/
|
||||
private static final IvoryTower INSTANCE = new IvoryTower();
|
||||
|
||||
/**
|
||||
* Private constructor so nobody can instantiate the class.
|
||||
*/
|
||||
private IvoryTower() {}
|
||||
|
||||
private static class IvoryTowerHolder {
|
||||
/**
|
||||
* Static to class instance of the class.
|
||||
*/
|
||||
private static final IvoryTower INSTANCE = new IvoryTower();
|
||||
}
|
||||
|
||||
/**
|
||||
* To be called by user to obtain instance of the class.
|
||||
*
|
||||
* @return instance of the singleton.
|
||||
*/
|
||||
public static IvoryTower getInstance() {
|
||||
return INSTANCE;
|
||||
return IvoryTowerHolder.INSTANCE;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user