标签:blog java 2014 log new sp on ef 应用
例如
public class DiskUtil {
private DiskUtil() { }
public static FUNC(){}
}
外面调用只能调用DiskUtil 的静态函数Func,而不能A a = new A();私有构造函数只能在函数内部调用,外部不能实例化,所以私有构造函数可以防止该类在外部被实例化
常见的应用是工具类和单例模式
package test.reflect;
public class Singleton {
private static Singleton s= null;
private Singleton() {
}
public static Singleton getInstance() {
if (s == null) {
synchronized (Singleton.class) {
if (s == null) {
s = new Singleton();
}
}
}
return s;
}
}
标签:blog java 2014 log new sp on ef 应用
原文地址:http://blog.csdn.net/liuwei063608/article/details/38753277