Here you can find the source of setField(Object object, Field field, Object value)
Parameter | Description |
---|---|
object | the given object |
field | the field to set |
value | the value to give the field |
public static void setField(Object object, Field field, Object value)
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Field; public class Main { /**/*from w w w .j a v a 2s. com*/ * Sets the value of a field for a given object, regardless if the field is accessible. * * @param object the given object * @param field the field to set * @param value the value to give the field */ public static void setField(Object object, Field field, Object value) { boolean accessible = field.isAccessible(); if (!accessible) { field.setAccessible(true); } try { field.set(object, value); } catch (IllegalAccessException shouldNeverHappen) { shouldNeverHappen.printStackTrace(); } if (!accessible) { field.setAccessible(false); } } }