Here you can find the source of setField(Object obj, Field field, Object value)
public static void setField(Object obj, Field field, Object value)
//package com.java2s; //License from project: Apache License import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.lang.invoke.MethodHandles; import java.lang.reflect.Field; public class Main { private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); public static void setField(Object obj, Field field, Object value) { field.setAccessible(true);/*from w w w. ja v a 2 s. c om*/ try { field.set(obj, value); } catch (IllegalAccessException e) { logger.error("set field failure", e); throw new RuntimeException(e); } } }