Here you can find the source of setFieldValue(Object obj, String fieldName, Object value)
public static boolean setFieldValue(Object obj, String fieldName, Object value)
//package com.java2s; //License from project: Apache License import java.lang.reflect.Field; public class Main { public static boolean setFieldValue(Object obj, String fieldName, Object value) { boolean result = true; try {/* w w w .j a v a 2 s . c om*/ Field field = obj.getClass().getDeclaredField(fieldName); boolean access = field.isAccessible(); field.setAccessible(true); field.set(obj, value); field.setAccessible(access); } catch (ReflectiveOperationException e) { result = false; } return result; } }