作用:copy继承类里面的相同key的value
public class BeanUtils{
public static void copy(Object c, Object c2) {
if (c != null && c2 != null) {
List<Field> fieldList = ReflectionUtils.getDeclaredFields(c);
Iterator var3 = fieldList.iterator();
while(var3.hasNext()) {
Field field = (Field)var3.next();
Object value = ReflectionUtils.getFieldValue(c2, field.getName());
if (value != null) {
ReflectionUtils.setFieldValue(c, field.getName(), value);
}
}
}
}
}
public class ReflectionUtils {
public static List<Field> getDeclaredFields(Object object) {
List<Field> fieldList = new ArrayList();
for(Class clazz = object.getClass(); clazz != Object.class; clazz = clazz.getSuperclass()) {
try {
fieldList.addAll(new ArrayList(Arrays.asList(clazz.getDeclaredFields())));
} catch (Exception var4) {
}
}
return fieldList;
}
public static Object getFieldValue(Object object, String fieldName) {
Field field = getDeclaredField(object, fieldName);
if (field == null) {
return null;
} else {
field.setAccessible(true);
try {
return field.get(object);
} catch (Exception var4) {
var4.printStackTrace();
return null;
}
}
}
public static void setFieldValue(Object object, String fieldName, Object value) {
Field field = getDeclaredField(object, fieldName);
if (field != null) {
field.setAccessible(true);
try {
if (field.getType().isPrimitive()) {
if (field.getType().equals(value.getClass())) {
field.set(object, value);
}
} else if (field.getType().isAssignableFrom(value.getClass())) {
field.set(object, value);
}
} catch (IllegalArgumentException var5) {
var5.printStackTrace();
} catch (IllegalAccessException var6) {
var6.printStackTrace();
}
}
}
}