Java Reflection Field Value Set setFieldvalue(T instance, E value, Field field)

Here you can find the source of setFieldvalue(T instance, E value, Field field)

Description

set Fieldvalue

License

Apache License

Declaration

public static <T, E> void setFieldvalue(T instance, E value, Field field) 

Method Source Code

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

import java.lang.reflect.Field;

public class Main {
    public static <T, E> void setFieldvalue(T instance, E value, Field field) {
        try {/*ww w.j ava2  s  .c  om*/
            field.setAccessible(true);
            field.set(instance, value);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(
                    String.format("Error while setting value (%s) into field (%s)", value, field.getName()), e);
        }
    }
}

Related

  1. setFieldValue(Object target, String fname, Class ftype, Object fvalue)
  2. setFieldValue(String fieldName, int fieldValue, Object board)
  3. setFieldValue(String inField, Object inObject, Object inValue)
  4. setFieldValue(String name, Object instance, int value, Class cl)
  5. setFieldValue(String name, String obfuscatedName, Class clazz, Object object, Object value)
  6. setFieldValue_internal(Object bean, Field field, Object value)
  7. setFieldValueForObject(Object object, String fieldName, Object value)
  8. setFieldValues(Object bean, Map valMap)
  9. setFieldValueWithPath(Object object, String path, Object value)