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(); } } }
本文来自博客园,作者:hjzqyx,转载请注明原文链接:https://www.cnblogs.com/hujunzheng/p/6808590.html