Java Reflection Field Value Set setFieldValue(Object obj, Field f, Object value)

Here you can find the source of setFieldValue(Object obj, Field f, Object value)

Description

set Field Value

License

Apache License

Declaration

public static void setFieldValue(Object obj, Field f, 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 obj, Field f, Object value) {
        try {//from   ww w.  j  a v a 2s. c  o m
            boolean accessible = f.isAccessible();
            try {
                f.setAccessible(true);
                f.set(obj, value);
            } finally {
                f.setAccessible(accessible);
            }
        } catch (IllegalArgumentException e) {
            throw e;
        } catch (IllegalAccessException e) {
            assert false;
        }
    }
}

Related

  1. setFieldValue(Object input, Object value, String fieldName)
  2. setFieldValue(Object instance, Field field, Object value)
  3. setFieldValue(Object instanceContainingField, String fieldName, Object fieldValue)
  4. setFieldValue(Object o, Class baseClass, Class fieldType, T value)
  5. SetFieldValue(Object o, String field, Object object)
  6. setFieldValue(Object obj, Field field, Object value)
  7. setFieldValue(Object obj, Field field, Object value)
  8. setFieldValue(Object obj, String field, Object value)
  9. setFieldValue(Object obj, String fieldName, Object value)