一个反射问题
JOptionPane.class.getField(s).getInt(null);
请问 getInt(null); 到底是个什么意思呢?
为什么我用个例子调试这个程序能编译 但运行会报找不到Field的错误呢?
public class Fan {
private final static int ZHANG = 99;
private final static int DONG = 88;
public static void main(String[] args) {
try {
System.out.println(Fan.class.getField("ZHANG").getInt(null));
}
catch(IllegalArgumentException e) {
e.printStackTrace();
}
catch(SecurityException e) {
e.printStackTrace();
}
catch(IllegalAccessException e) {
e.printStackTrace();
}
catch(NoSuchFieldException e) {
e.printStackTrace();
}
}
}