"""
单件模式
"""
public class Singleton{
private static Singleton uniqueInstance;
private Singleton(){}
public static Singleton getInstance(){
if (uniqueInstance == null){
uniqueInstance = new Singleton();
}
return uniqueInstance
}
}
public class Singleton{
private static Singleton uniqueInstance;
private Singleton(){}
public static synchronized Singleton getInstance(){
if (uniqueInstance == null){
uniqueInstance = new Singleton()
}
return uniqueInstance
}
}
headfirsh设计模式——单件模式例子
于 2022-02-02 15:45:39 首次发布