反射的应用
/**
* 判断一个对象中的全部属性是否为空,false-有属性值不全为空,true-属性值全为空
* @return
*/
public static boolean objectIsEmpty(Object o) {
boolean flag = false;
Class aClass = o.getClass();
Field[] declaredFields = aClass.getDeclaredFields();
try {
for (Field field : declaredFields) {
field.setAccessible(true);
if (field.get(o) == null) {
flag = true;
} else {
flag = false;
break;
}
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return flag;
}