标签:size lis return field illegal declare end trace 对象
private static Field[] getAllFields(Object object) {
Class clazz = object.getClass();
List<Field> fieldList = new ArrayList<>();
while (clazz != null) {
fieldList.addAll(new ArrayList<>(Arrays.asList(clazz.getDeclaredFields())));
clazz = clazz.getSuperclass();
}
Field[] fields = new Field[fieldList.size()];
fieldList.toArray(fields);
return fields;
}
private StringBuilder compareContract(Object obj, Object obj2) {
StringBuilder stringBuilder = new StringBuilder();
try {
Field[] fields = getAllFields(obj);
for (int j = 0; j < fields.length; j++) {
fields[j].setAccessible(true);
// 字段值
if (!fields[j].get(obj).equals(fields[j].get(obj2))) {
stringBuilder.append(obj2.get字段());
stringBuilder.append(fields.getName()).append("、"));
}
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return stringBuilder;
}
标签:size lis return field illegal declare end trace 对象
原文地址:https://www.cnblogs.com/lsys/p/11163606.html