Here you can find the source of setFieldValue(Object receiver, String fieldName, Object value)
public static void setFieldValue(Object receiver, 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 receiver, String fieldName, Object value) { Field field = getField(receiver, fieldName); if (field == null) { return; }/* w ww.ja va2s . com*/ try { field.set(receiver, value); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } } private static Field getField(Object receiver, String fieldName) { if (receiver == null) { return null; } return getFieldByClass(receiver.getClass(), fieldName); } private static Field getFieldByClass(Class<?> clazz, String fieldName) { if (clazz == null || fieldName == null) { return null; } try { return clazz.getField(fieldName); } catch (NoSuchFieldException e) { e.printStackTrace(); } return null; } }