私有构造函数产生对象
public class Hello {
int sum;
private Hello(){}
public void f(){
System.out.println( "****** ");
}
}
大家有没有办法在其它类中调用f()这个函数啊?
------解决方案--------------------Class c = Class.forName( "Hello ");
Constructor[] t = c.getDeclaredConstructors();
t[0].setAccessible(true);
Object t_ = t[0].newInstance(null);
Method method = c.getDeclaredMethod( "f ", null);
method.invoke(t_, null);
----------------------------------
LZ有结贴的习惯吗?