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;
}

}

原文地址:https://www.cnblogs.com/liubaihui/p/8649726.html