public class SingletonTest {
/**
* 饿汉式
*/
//通过new在本类中创建本类对象
private static SingletonTest instance = new SingletonTest();
//私有化构造函数
private SingletonTest(){};
//提供一个方法,返回本类的对象
public static SingletonTest getInstance(){
return instance;
}
}
单例
最新推荐文章于 2023-03-10 15:41:36 发布