Here you can find the source of setFieldValue(Object target, String field, Object value)
public final static void setFieldValue(Object target, String field, Object value)
//package com.java2s; /*/*from w w w. java 2 s.c o m*/ * BJAF - Beetle J2EE Application Framework * ???J2EE??????????? * ??????2003-2015 ??? (www.beetlesoft.net) * * ?????????????????? *<http://www.apache.org/licenses/LICENSE-2.0> *???????????????????????? * * ??????????????????????????????? * ??? <yuhaodong@gmail.com/>. */ import java.lang.reflect.Field; public class Main { public final static void setFieldValue(Object target, String field, Object value) { try { Class<?> obj = target.getClass(); Field[] fields = obj.getDeclaredFields(); for (int i = 0; i < fields.length; i++) { fields[i].setAccessible(true); if (field.equals(fields[i].getName())) { fields[i].set(target, value); break; } } } catch (Exception e) { throw new RuntimeException(e); } } }