com.lq.comment.util.ClassUtil Maven / Gradle / Ivy
package com.lq.comment.util;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;
public class ClassUtil {
private static final String objectType = "java.lang.Object";
public static void getDeclaredFields(Class> aClass, List declaredFieldList){
Class> superclass = aClass.getSuperclass();
if (superclass.getName().equals(objectType)){
Field[] declaredFields = aClass.getDeclaredFields();
declaredFieldList.addAll(Arrays.asList(declaredFields));
}else {
Field[] declaredFields = aClass.getDeclaredFields();
declaredFieldList.addAll(Arrays.asList(declaredFields));
aClass = superclass;
getDeclaredFields(aClass,declaredFieldList);
}
}
}