java 反射获取类的静态属性值

public class AppTest {
    private NodeClass nodeClass;

    public static String  hehe = "hehe";

    public String xixi = "xixi";

    public void test() {
        Field[] fields = AppTest.class.getDeclaredFields();
        try {
            for (Field field : fields) {
                field.setAccessible(true);
                if(field.getType().toString().endsWith("java.lang.String") && Modifier.isStatic(field.getModifiers()))
                    System.out.println(field.getName() + " , " + field.get(AppTest.class));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

 

posted @ 2017-05-04 18:10  hjzqyx  阅读(10803)  评论(0编辑  收藏  举报