ITeye博客

单例模式之饿汉模式

bigSeven · 2015-12-05 17:02 · java设计模式 · 编程语言 · 单例模式 · Java设计模式 · 饿汉模式 · Markdown

package mode;

 

/**

 * 单例模式之饿汉模式

 * @author gaoq

 * @date 2015-12-5 下午4:50:13

 */

public class SingletonMode {

 

private static final SingletonMode singletonMode = new SingletonMode();

 

private SingletonMode(){

 

}

 

public static SingletonMode getInstance(){

return singletonMode;

}

 

public void test(){

System.out.println("你好,饿汉");

}

 

}

============================================

package mode;

/**

 * 测试类

 * @author gaoq

 * @date 2015-12-5 下午4:54:50

 */

public class TestMain {

 

public static void main(String[] args) {

SingletonMode.getInstance().test();

}

 

}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。