Here you can find the source of setFieldValue(Object obj, String fieldname, Object value)
public static void setFieldValue(Object obj, String fieldname, Object value)
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Field; public class Main { public static void setFieldValue(Object obj, String fieldname, Object value) { Class<?> clazz = obj.getClass(); do {/* w w w .jav a2 s .co m*/ try { Field field = clazz.getDeclaredField(fieldname); field.setAccessible(true); field.set(obj, value); } catch (Throwable t) { } } while ((clazz = clazz.getSuperclass()) != null); } }