通过反射获取字段值
/* from N o w J a v a . c o m - 时 代 Java */ import java.lang.reflect.Field; public class Main{ @SuppressWarnings("unchecked") public static <T> T getFieldValue(Object bean, String name) { Field field; T result = null; try { field = bean.getClass().getDeclaredField(name); field.setAccessible(true); result = (T) field.get(bean); } catch (Exception e) { e.printStackTrace();/* 来自 时代Java公众号 - N o w J a v a . c o m*/ } return result; } @SuppressWarnings("unchecked") public static <T> T getFieldValue(Object bean, Field field) { T result = null; try { field.setAccessible(true);