Here you can find the source of setField(Object instance, String sField, Object value)
public static void setField(Object instance, String sField, Object value) throws SecurityException, NoSuchFieldException, ClassNotFoundException, IllegalArgumentException, IllegalAccessException
//package com.java2s; import java.lang.reflect.Field; public class Main { public static void setField(Object instance, String sField, Object value) throws SecurityException, NoSuchFieldException, ClassNotFoundException, IllegalArgumentException, IllegalAccessException { Field field = instance.getClass().getDeclaredField(sField); field.setAccessible(true);/* ww w . ja v a 2s. c om*/ field.set(instance, value); } }