java单例模式

Java单例模式

1,懒汉式

例如

public class Test01 {
private Test01(){};
private static Test01 test01;

public static Test01 getInstance(){
return test01=new Test01();
}

 

2,饿汉式

例如

public class Test01 {
private Test01(){};
private static Test01 test01=new Test01();

public static Test01 getInstance(){
return test01;
}

}

posted @ 2018-03-26 11:22  刘百会  阅读(213)  评论(3编辑  收藏  举报