不多BB,直接上个最好用的,线程安全的,使用静态内部类持有的静态对象
public class Singleton {
private Singleton(){}
private static class SingletonHolder{
private SingletonHolder(){}
private static Singleton s = new Singleton();
}
public static Singleton getInstance(){
return SingletonHolder.s;
}
}