在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运行结果----异常】
【myeclipse运行结果----正常】
把Public class Test {
private int id;
private int age;
private Double double1 = 123.4;
public Test() {
};
private void method1() {
};
private void method2() {
};
private void method3() {
};
}复制出来起名Test.java放在同级目录下,在运行就好了,亲
看看eclipse设置里Java编译器
运行环境没配置吧;
没有找到类,应该是缺少jar包,myeclipse会自动加载一些包,所以不报错
把Public class Test {
private int id;
private int age;
private Double double1 = 123.4;
public Test() {
};
private void method1() {
};
private void method2() {
};
private void method3() {
};
}复制出来起名Test.java放在同级目录下,在运行就好了,亲