Here you can find the source of setFieldValue(Object object, String fieldName, Object value)
public static void setFieldValue(Object object, String fieldName, Object value) throws NoSuchFieldException, IllegalAccessException
//package com.java2s; import java.lang.reflect.Field; public class Main { public static void setFieldValue(Object object, String fieldName, Object value) throws NoSuchFieldException, IllegalAccessException { Field field = getDeclaredField(object, fieldName); if (!field.isAccessible()) { field.setAccessible(true);//w w w. j a v a 2 s .c o m } try { field.set(object, value); } catch (IllegalAccessException e) { throw e; } } public static Field getDeclaredField(Object object, String fieldName) throws NoSuchFieldException { return getDeclaredField(object.getClass(), fieldName); } @SuppressWarnings("unchecked") public static Field getDeclaredField(Class clazz, String fieldName) throws NoSuchFieldException { return clazz.getDeclaredField(fieldName); } }