Here you can find the source of setField(Object object, String field, Object value)
public static void setField(Object object, String field, Object value)
//package com.java2s; //License from project: Apache License import java.lang.reflect.Field; public class Main { public static void setField(Object object, String field, Object value) { if (object == null || field == null) return; try {//from www . j a v a 2 s . c o m Field target = object.getClass().getDeclaredField(field); target.setAccessible(true); target.set(object, value); } catch (Exception ignored) { } } }