java 使用反射获取属性名,和值
2020-12-29 23:30
标签:ack color field div ble 字段 ssi 使用 class java 使用反射获取属性名,和值 标签:ack color field div ble 字段 ssi 使用 class 原文地址:https://www.cnblogs.com/nongzihong/p/13022417.html Class> aClass = xxx实体类.getClass();
//得到属性
Field field = null;
try {
field = aClass.getDeclaredField("字段名xxxx");
//打开私有访问
field.setAccessible(true);
//获取属性
String name = field.getName();
//获取属性值
String subjectType = (String) field.get(xxx实体类);
System.out.println(subjectType);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}