package com.test;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
public class Test_5 {
public static final int a = 111;
public static final int b = 222;
public static final int c = 333;
public static final int d = 444;
public static void main(String[] args) {
try {
Class c = Class.forName("com.test.Test_5");
Field[] fields = c.getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
String m = Modifier.toString(fields[i].getModifiers());
if (m != null && m.indexOf("final") > -1) {
System.out.println(fields[i].getInt(int.class));
}
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
java反射类成员变量
最新推荐文章于 2021-02-25 10:40:52 发布