java 反射应用
/*** * * @param obj * @param propertyName :name of property * @return * @throws SecurityException * @throws NoSuchFieldException * @throws IllegalArgumentException * @throws IllegalAccessException */public static Object getObjectValue(Object obj, String propertyName)throws SecurityException, NoSuchFieldException,IllegalArgumentException, IllegalAccessException {if (StringUtils.isEmpty(propertyName)) {return null;}Class<?> clazz = obj.getClass();Field name = clazz.getDeclaredField(propertyName);name.setAccessible(true);return name.get(obj);}
?说明:依赖的jar:commons-lang-2.6.jar
?