/**
* 反射实现集合赋值给对象
* @param array
* @return
* @throws IntrospectionException
* @throws InstantiationException
* @throws IllegalAccessException
* @throws IllegalArgumentException
* @throws InvocationTargetException
*/
public static Object invokeMethod(String[] array) throws IntrospectionException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Object object =Violation.class.newInstance();
Field[] fields =Violation.class.getDeclaredFields();
for (int i = 0; i < array.length; i++) {
Field f = fields[i];
PropertyDescriptor pd = new PropertyDescriptor(f.getName(), Violation.class);
Method m = pd.getWriteMethod();
m.invoke(object, array[i]);
}
return object;
}
▄█▀█●各位老铁,如果我的代码能够帮助到你,请给我一个赞吧!