JAVA类获取值的问题
我又一个类,里面是这么写的
public static final short A = 50;
// /////////////
// 各模块通用的消息
// ////////////
private static short B = A;
public static final short C = ++A;
public static final short D = ++A;
public static final short E = ++A;
public static final short F = ++A;
public static final short G = ++A;
public static final short H = ++A;
public static final short I = ++A;
public static final short J = ++A;
public static final short K = ++A;
public static final short L = ++A;
public static final short M = ++A;
public static final short N = ++A;
public static final short O = ++A;
public static final short P = ++A;
public static final short Q = ++A;
有没有什么方法 可以一次性把里面所有的对象名字和对象值打印出来!谢谢!!
------解决方案--------------------假设你的类名为AA
AA aa = new AA();
for (Field f : aa.getClass().getDeclaredFields()) {
f.setAccessible(true);
System.out.println(f.getName() + "==" + f.get(aa));
}
但是你的这个写法好像有问题。
A声明为final时,++A操作报错。