单例模式
/*//饿汉式
class SingleClass{
private final static SingleClass INSTANCE = new SingleClass();
private SingleClass(){}
public static SingleClass newInstance(){
return INSTANCE;
}
}*/
//懒汉式
class SingleClass{
private static SingleClass INSTANCE = null;
private SingleClass(){}
public static synchronized SingleClass newInstance(){
if(INSTANCE == null){
INSTANCE = new SingleClass();
}
return INSTANCE;
}
}
sorta