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

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

Description

set Field Value

License

Open Source License

Declaration

public static void setFieldValue(Object target, Field field,
            Object value) throws IllegalArgumentException,
            IllegalAccessException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.lang.reflect.Field;

public class Main {
    public static void setFieldValue(Object target, Field field,
            Object value) throws IllegalArgumentException,
            IllegalAccessException {
        if (field.isAccessible()) {
            field.set(target, value);//from www.  j a v  a  2  s.  c o m
        } else {
            field.setAccessible(true);
            field.set(target, value);
            field.setAccessible(false);
        }
    }
}

Related

  1. setFieldValue(Object objectInstance, String fieldName, Object valueToSet)
  2. setFieldValue(Object pojo, Field field, Object value)
  3. setFieldValue(Object receiver, String fieldName, Object value)
  4. setFieldValue(Object target, Class targetClass, String fieldName, Object value)
  5. setFieldValue(Object target, Field field, Object newValue)
  6. setFieldValue(Object target, Object mock, final Field field)
  7. setFieldValue(Object target, String field, Object value)
  8. setFieldValue(Object target, String fieldName, Object fieldValue)
  9. setFieldValue(Object target, String fieldName, Object value)