单例模式
如题
Java中单例模式的使用有很多方法
1.懒汉式,饿汉式,等等
用到哪个整理哪个
懒汉式
饿汉式
双检查
private static CameraPhotographPresenter sInstance;
private CameraPhotographPresenter(){
}
public static CameraPhotographPresenter getInstance() {
if(sInstance==null){
synchronized (CameraPhotographPresenter.class){
if(sInstance==null){
sInstance = new CameraPhotographPresenter();
}
}
}
return sInstance;
}