【发布时间】:2011-03-11 14:30:33
【问题描述】:
我正在使用这样的枚举单例模式:
public enum LicenseLoader implements ClientLicense {
INSTANCE;
/**
* @return an instance of ClientLicense
*/
public static ClientLicense getInstance() {
return (ClientLicense)INSTANCE;
}
...rest of code
}
现在我想返回接口并隐藏我们实际上正在使用枚举的事实。我希望客户端使用 getInstance() 而不是 LicenseLoader.INSTANCE,因为有一天我可能会决定在必要时使用不同的模式。
是否可以将 INSTANCE 设为枚举私有?
【问题讨论】:
标签: java singleton enums private