Java Reflection Field Value Set setFieldValueForObject(Object object, String fieldName, Object value)

Here you can find the source of setFieldValueForObject(Object object, String fieldName, Object value)

Description

set Field Value For Object

License

GNU General Public License

Declaration

public static void setFieldValueForObject(Object object, String fieldName, Object value)
            throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException 

Method Source Code


//package com.java2s;
/*//  w  w w. jav  a2  s  . com
 * This software is licensed under the GPL v2 (http://www.gnu.org/licenses/gpl-2.0.html).
 */

import java.lang.reflect.Field;

public class Main {
    public static void setFieldValueForObject(Object object, String fieldName, Object value)
            throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException {
        Field field = object.getClass().getDeclaredField(fieldName);
        field.setAccessible(true);
        field.set(object, value);
    }
}

Related

  1. setFieldValue(String inField, Object inObject, Object inValue)
  2. setFieldValue(String name, Object instance, int value, Class cl)
  3. setFieldValue(String name, String obfuscatedName, Class clazz, Object object, Object value)
  4. setFieldvalue(T instance, E value, Field field)
  5. setFieldValue_internal(Object bean, Field field, Object value)
  6. setFieldValues(Object bean, Map valMap)
  7. setFieldValueWithPath(Object object, String path, Object value)
  8. setFieldValueWithSetterMethod(Object target, Object value, Class clazz, Field field)
  9. setFieldValueX(Object target, String field, Object value)