Here you can find the source of setFieldValue(Object object, String fieldName, Object value)
public static void setFieldValue(Object object, String fieldName, Object value)
//package com.java2s; //License from project: Apache License import java.lang.reflect.Field; public class Main { public static void setFieldValue(Object object, String fieldName, Object value) { Field field = getAccessibleField(object, fieldName); if (field == null) { throw new IllegalArgumentException("Could not find field " + fieldName); }/*from w w w. j a va 2s.com*/ try { field.set(object, value); } catch (IllegalAccessException e) { } } public static Field getAccessibleField(final Object object, final String fieldName) { for (Class<?> superClass = object.getClass(); superClass != Object.class;) { try { Field field = superClass.getDeclaredField(fieldName); field.setAccessible(true); return field; } catch (NoSuchFieldException e) { return null; } } return null; } }