/** * MethodName: getReflection <br> * Descrição: 解析 respxml 在通过反射设置对象属性值 * Usuário: liqijing * Data: 2015-7-19 下午 12:42:55 * @param clzzName * @param respxml * @return * @THONGFoundE InstantiationException * @throws SecurityException * @throws NoSuchFieldException */public static <T> Object getReflection(String clzzName , String respXML) throws ClassNotFoundException, DocumentException, IllegalArgumentException, IllegalAccessException, InstantiationException, SecurityException, NoSuchFieldException{Object o = Class.ForName (clzzName) .NewInstance (); classe clz = classe.ForName (clzzName) .NewInstance (). GetClass (); document doc = null; doc. it = el.ElementIterator (); while (it.hasNext ()) {elemento elt = (elemento) it.next (); if (f.getName (). Equals (elt.getName ())) {f = clz.getDeclaredfield (elt.getName ()); o;}Caros:
在开发过程中有类似的需求通过反射动态设置属性值 , 希望有帮助。也很高兴与大家分享 , 谢谢。
以上这篇 Java 通过反射机制动态设置对象属性值的方法就是小编分享给大家的全部内容了 , 希望能给大家一个参考 , 也希望大家多多支持武林网。