Java Reflection Field Value Set setFieldValue(Object object, Field field, Object value)

Here you can find the source of setFieldValue(Object object, Field field, Object value)

Description

set Field Value

License

Apache License

Declaration

public static void setFieldValue(Object object, Field field,
            Object value) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.lang.reflect.Field;

public class Main {
    public static void setFieldValue(Object object, Field field,
            Object value) {// www.  j av a  2  s. com
        try {
            setAccessibleIfNeeded(field);
            field.set(object, value);
        } catch (final Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static void setAccessibleIfNeeded(Field field) {
        if (!field.isAccessible()) {
            field.setAccessible(true);
        }
    }
}

Related

  1. setFieldValue(Object obj, String fieldName, Object value)
  2. setFieldValue(Object obj, String fieldName, Object value)
  3. setFieldValue(Object obj, String fieldName, Object value)
  4. setFieldValue(Object obj, String fieldName, String fieldValue)
  5. setFieldValue(Object obj, String name, Object value)
  6. setFieldValue(Object object, String fieldName, Object fieldValue)
  7. setFieldValue(Object object, String fieldName, Object fieldValue)
  8. setFieldValue(Object object, String fieldName, Object fieldValue)
  9. setFieldValue(Object object, String fieldName, Object value)