Field[] field = behavior.getClass().getDeclaredFields();
for (int i = 0; i < field.length; i++) {
String name = field[i].getName();
name = name.substring(0, 1).toUpperCase() + name.substring(1);//找到首位改成大写形式
String type = field[i].getGenericType().toString();//字段类型
if (type.equals("class java.lang.String")) {
Method m;
String value;
try {
m = behavior.getClass().getMethod("get" + name);
value = (String) m.invoke(behavior);
if (value.equals("x")) {//value是获取到的值
mapdata.put("behavior", name);//name是字段名
}
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
}
}