反射获取属性值并设置属性值

public static void getSuperClass(Class<?> clazz, AbstractInfo source, AbstractInfo target){
Field[] fields = clazz.getDeclaredFields();
for(int i = 0 ;i< fields.length; i++){
Field field = fields[i];
field.setAccessible(true);
Object obj = null;
try {
if(field.getType() == Map.class){
Map<String, String> viewParaMap = new HashMap<String, String>();
field.set(target,viewParaMap);
}else{
obj = field.get(source);
field.set(target,obj);
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
if(fields.length > 0){
getSuperClass(clazz.getSuperclass(),source,target);
}
}

上一篇:Chrome下的语音控制框架MyVoix.js使用篇(二)


下一篇:初识反射 Java