日期:2014-05-20 浏览次数:20998 次
在d类中使用反射实例化一个a类的对象,调用它的方法
import java.lang.reflect.Constructor;
public class d {
public static void main(String[] args)throws Exception {
Class c = Class.forName("a");
Object o=a.newInstance();//这是创建构造方法
Method[] methods=c.getMethods();
for(Method m:methods)
{
if(m.getName().equals("f"))
{
m.invoke(o);
}
}
}
}
------解决方案--------------------