Here you can find the source of setField(Object obj, String fieldname, Object value)
Parameter | Description |
---|---|
obj | a parameter |
fieldname | a parameter |
value | a parameter |
public static void setField(Object obj, String fieldname, Object value)
//package com.java2s; import java.lang.reflect.Field; public class Main { /**/*from w w w. j a v a2 s . co m*/ * * @param obj * @param fieldname * @param value */ public static void setField(Object obj, String fieldname, Object value) { try { Field field = obj.getClass().getField(fieldname); field.setAccessible(true); field.set(obj, value); } catch (Exception e) { // ignore } } }