public static List<Field> getAllDeclaredFields(Class<?> clazz) { List<Field> allFields = new ArrayList<>(); Class<?> superClass = clazz.getSuperclass(); // 获取当前类声明的所有字段 Field[] declaredFields = clazz.getDeclaredFields(); allFields.addAll(Arrays.asList(declaredFields)); // 如果存在父类,则递归获取父类的字段 if (superClass != null) { allFields.addAll(getAllDeclaredFields(superClass)); } return allFields; }
标签:allFields,declaredFields,clazz,获取,superClass,父类,属性 From: https://www.cnblogs.com/deepalley/p/18120310