Here you can find the source of setField(Class> cl, String name, Object obj, Object value)
public static void setField(Class<?> cl, String name, Object obj, Object value) throws ReflectiveOperationException
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Field; public class Main { public static void setField(Class<?> cl, String name, Object obj, Object value) throws ReflectiveOperationException { Field field = cl.getDeclaredField(name); field.setAccessible(true);// w ww.j a v a 2 s . c o m field.set(obj, value); } }