Here you can find the source of setFieldValue(Object obj, Field f, Object value)
public static void setFieldValue(Object obj, Field f, Object value)
//package com.java2s; //License from project: Apache License import java.lang.reflect.Field; public class Main { public static void setFieldValue(Object obj, Field f, Object value) { try {//from ww w. j a v a 2s. c o m boolean accessible = f.isAccessible(); try { f.setAccessible(true); f.set(obj, value); } finally { f.setAccessible(accessible); } } catch (IllegalArgumentException e) { throw e; } catch (IllegalAccessException e) { assert false; } } }