首页>代码>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日
最近浏览更多
cuiyuu  LV1 2023年2月15日
ROCK森  LV12 2022年11月7日
qijiqiji  LV1 2022年6月13日
wangdengzhe  LV7 2022年5月7日
为了水掉6位用户名  LV4 2022年3月4日
mqqiad  LV8 2021年8月22日
xb1406112453  LV5 2021年2月27日
ysy520  LV8 2020年12月2日
Azure1  LV3 2020年8月11日
卡卡罗特  LV8 2020年7月24日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友