遍历User的对象的属性名和值(java.lang.reflect.Field)
public void traverse(Object object){
Field[] fields = object.getClass().getDeclaredFields();
for (Field field : fields) {
field.setAccessible(true);
try {
System.out.print(field.getName() + ":"
+ field.get(object) + "\t");
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}