Java Reflection Field Set setField(Field field, Object classWithField, Object value)

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

Description

set Field

License

Creative Commons License

Parameter

Parameter Description
Field The field to set.
Object The value to set.

Declaration

public static void setField(Field field, Object classWithField, Object value) 

Method Source Code


//package com.java2s;
//License from project: Creative Commons License 

import java.lang.reflect.Field;

public class Main {
    /**//from ww w .j a v a  2 s.  c  o m
     * @param Field The field to set.
     * @param Object The class of the field.
     * @param Object The value to set.
     */
    public static void setField(Field field, Object classWithField, Object value) {
        try {
            field.set(classWithField, value);
        } catch (IllegalArgumentException | IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}

Related

  1. setField(Class clazz, T instance, String fieldName, Object value)
  2. setField(Class clazz, T instance, String fieldName, Object value)
  3. setField(Field f, Object instance, Object value)
  4. setField(Field f, Object this_, Object value)
  5. setField(Field field, @Nullable Object instance, Object thing)
  6. setField(Field field, Object instance, Object value)
  7. setField(Field field, Object obj, String value)
  8. setField(Field field, Object objToSet, Object value)
  9. setField(Field field, Object target, Object value)