Here you can find the source of setField(Object source, String fieldName, Object value)
public static void setField(Object source, String fieldName, Object value) throws Exception
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Field; public class Main { public static void setField(Object source, String fieldName, Object value) throws Exception { Class cl = source.getClass(); Field f = cl.getDeclaredField(fieldName); f.setAccessible(true);//from ww w . j av a2 s. c om f.set(source, value); } }