嗨,能否有人告诉我如何实例化下面给定的单例课程的正确方法?
public class BillPughSingleton {
private BillPughSingleton(){}
private static class SingletonHelper{
private static final BillPughSingleton INSTANCE = new BillPughSingleton();
}
public static BillPughSingleton getInstance(){
return SingletonHelper.INSTANCE;
}
}
最佳答案
尝试:
BillPughSingleton bill = BillPughSingleton.getInstance();