Here you can find the source of setField(Field field, Object target, Object value)
public static void setField(Field field, Object target, Object value)
//package com.java2s; //License from project: LGPL import java.lang.reflect.Field; import java.lang.reflect.Modifier; public class Main { public static void setField(Field field, Object target, Object value) { if (!Modifier.isPublic(field.getModifiers())) { field.setAccessible(true);//from w w w . j a va 2 s . c o m } try { field.set(target, value); } catch (IllegalAccessException iae) { throw new IllegalArgumentException("Could not set field " + field, iae); } } }