Here you can find the source of setField(Object instance, String name, Object obj)
public static void setField(Object instance, String name, Object obj)
//package com.java2s; //License from project: Apache License import java.lang.reflect.Field; public class Main { public static void setField(Object instance, String name, Object obj) { try {//from w ww. j av a 2 s. co m Field f = instance.getClass().getDeclaredField(name); f.setAccessible(true); f.set(instance, obj); } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) { throw new RuntimeException(e); } } }