首页>代码>23种设计模式的java代码示例>/DesignPattern/src/dps_01_build_type/dp01_singleton/eager/example1/EagerSingleton.java
package dps_01_build_type.dp01_singleton.eager.example1; /** * 饿汉式单例(唯一角色即类本身):<br> * 在类被加载的时候,唯一实例已经被创建。这个设计模式在Java中容易实现,在别的语言中难以实现。<br> * @author Administrator */ public class EagerSingleton { /**私有的(private)唯一(static final)实例成员,在类加载的时候就创建好了单例对象*/ private static final EagerSingleton instance = new EagerSingleton(); /** * 私有构造函数,避免从外部创建实例 */ private EagerSingleton() { } /** * 静态工厂方法,返回此类的唯一实例.<br> * @return EagerSingleton */ public static EagerSingleton getInstance() { return instance; } }
最近下载更多
xb1406112453 LV5
2021年2月27日
moomin709 LV24
2020年11月17日
shoucheng LV19
2020年6月17日
chinaboyme LV3
2020年4月1日
yuanjh2001 LV7
2020年3月25日
MaNong码农 LV7
2020年1月4日
906396135 LV7
2019年10月31日
redredLZ LV4
2019年10月21日
jeff2020 LV2
2019年9月28日
aisuzhen LV10
2019年9月17日