Here you can find the source of setField(Object target, String name, Object value)
Parameter | Description |
---|---|
target | a parameter |
name | a parameter |
value | a parameter |
public static boolean setField(Object target, String name, Object value)
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Field; public class Main { /**// www . j a v a 2 s . co m * Set the field identified by name to the given value. * @param target * @param name * @param value * @return true on success, false if field wasn't found. */ public static boolean setField(Object target, String name, Object value) { try { Field field = target.getClass().getDeclaredField(name); field.setAccessible(true); field.set(target, value); return true; } catch (NoSuchFieldException e) { return false; } catch (Exception e) { throw new RuntimeException(e); } } }