Java Reflection Field Set setField(final Field field, final Object object, final Object value)

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

Description

Sets the supplied value of the supplied field on the supplied object.

License

Open Source License

Parameter

Parameter Description
field of the object to set
object that has the field
value to set

Exception

Parameter Description
IllegalArgumentExceptionif the field cannot be set

Declaration

public static void setField(final Field field, final Object object, final Object value) 

Method Source Code


//package com.java2s;
/* See LICENSE for licensing and NOTICE for copyright. */

import java.lang.reflect.Field;

public class Main {
    /**//from w w  w  .j  a  v a  2s.co  m
     * Sets the supplied value of the supplied field on the supplied object.
     *
     * @param  field  of the object to set
     * @param  object  that has the field
     * @param  value  to set
     *
     * @throws  IllegalArgumentException  if the field cannot be set
     */
    public static void setField(final Field field, final Object object, final Object value) {
        try {
            field.set(object, value);
        } catch (IllegalAccessException e) {
            throw new IllegalArgumentException(e);
        }
    }
}

Related

  1. setField(Field field, Object target, Object value)
  2. setField(Field field, Object target, Object value)
  3. setField(Field field, T newValue, Object instance)
  4. setField(Field field, U instance, Object value)
  5. setField(final Field field, final Object instance, final Object value)
  6. setField(final O object, final String fieldName, final V value)
  7. setField(final Object instance, final String fieldName, final T value)
  8. setField(final Object obj, final String fieldName, final int value)
  9. setField(final Object obj, final String fieldName, final Object value)