本帖最后由 何羡玉 于 2013-5-5 21:26 编辑
我创建了一个类,想通过反射建立实例对象,调用里面的方法,编译正确,运行异常,是哪里错啊。
package enhanceTest;
import java.lang.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
public class reflectTest {
reflectTest(){}
public void printString()
{
System.out.println("反射出来了");
}
/**
* @param args
* @throws ClassNotFoundException
* @throws SecurityException
* @throws NoSuchMethodException
* @throws InvocationTargetException
* @throws IllegalArgumentException
* @throws IllegalAccessException
* @throws InstantiationException
*/
public static void main(String[] args) throws Exception
{
Constructor constructor=Class.forName("reflectTest").getConstructor(null);
reflectTest re=(reflectTest)constructor.newInstance(null);
re.printString();
}
}
|
|