/**
* 获取类的所有字段
* @param clazz
* @param <T>
* @return
*/
public static <T> Field[] getAllDeclaredFields(Class<T> clazz) {
List<Field[]> fieldArrayList = new ArrayList<Field[]>();
while (clazz != null) {
fieldArrayList.add(clazz.getDeclaredFields());
clazz = (Class<T>) clazz.getSuperclass();
}
int fieldCount = 0;
int fieldIndex = 0;
for (Field[] fieldArray : fieldArrayList) {
fieldCount = fieldCount + fieldArray.length;
}
Field[] allFields = new Field[fieldCount];
for (Field[] fieldArray : fieldArrayList) {
for (Field field : fieldArray) {
allFields[fieldIndex++] = field;
}
}
return allFields;
}
获取类的所有字段(包括父类)
最新推荐文章于 2024-07-20 02:56:19 发布