Here you can find the source of setFieldValue(Object obj, String name, Object value)
private static void setFieldValue(Object obj, String name, Object value)
//package com.java2s; import java.lang.reflect.Field; public class Main { private static void setFieldValue(Object obj, String name, Object value) { Field field;// w ww .j av a2 s . c o m try { field = obj.getClass().getDeclaredField(name); field.setAccessible(true); field.set(obj, value); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } }