读书人

java 反照应用

发布时间: 2013-08-01 15:23:18 作者: rapoo

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

?

读书人网 >编程

热点推荐