eclipse关于反射的代码都运行异常,同样的代码复制到记事本或myeclipse就可以正常运行,这是怎么回事
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
public class Demo1 {
public static void main(String[] args) throws Exception {
Class cs = Class.forName("Test");
Field[] ff = cs.getDeclaredFields();
for (Field f : ff) {
System.out.println(f);
}
Method[] mm = cs.getDeclaredMethods();
for (Method m : mm) {
System.out.println(m);
}
Constructor[] cc = cs.getConstructors();
for (Constructor c : cc) {
System.out.println(c);
}
}
}
class Test {
private int id;
private int age;
private Double double1 = 123.4;
public Test() {
};
private void method1() {
};
private void method2() {
};
private void method3() {
};
}
我的eclipse版本是Version: Mars Release (4.5.0)运行了你的代码,是正常的,输出结果如下:
private int Test.id
private int Test.age
private java.lang.Double Test.double1
private void Test.method3()
private void Test.method2()
private void Test.method1()
public Test()
不知道你是什么版本呢?代码是没有问题的。
不知道你的代码是什么样?不知道你的异常是什么样?
贴出来看看,应该还是有个问题