Here you can find the source of setFieldValueForObject(Object object, String fieldName, Object value)
public static void setFieldValueForObject(Object object, String fieldName, Object value) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException
//package com.java2s; /*// w w w. jav a2 s . com * This software is licensed under the GPL v2 (http://www.gnu.org/licenses/gpl-2.0.html). */ import java.lang.reflect.Field; public class Main { public static void setFieldValueForObject(Object object, String fieldName, Object value) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException { Field field = object.getClass().getDeclaredField(fieldName); field.setAccessible(true); field.set(object, value); } }