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

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

Description

set Field

License

Apache License

Declaration

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

Method Source Code

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

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.invoke.MethodHandles;

import java.lang.reflect.Field;

public class Main {
    private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

    public static void setField(Object obj, Field field, Object value) {
        field.setAccessible(true);/*from   w w w. ja v a  2  s.  c  om*/
        try {
            field.set(obj, value);
        } catch (IllegalAccessException e) {
            logger.error("set field failure", e);
            throw new RuntimeException(e);
        }
    }
}

Related

  1. setField(Object o, String fieldName, Object inject)
  2. setField(Object o, String fieldName, Object value)
  3. setField(Object o, String fieldName, Object value)
  4. setField(Object o, String name, Object value)
  5. setField(Object obj, Class fieldOwner, String fieldName, Object value)
  6. setField(Object obj, Object value, String fieldName)
  7. setField(Object obj, Object value, String fieldName)
  8. setField(Object obj, String fieldName, Object fieldValue)
  9. setField(Object obj, String fieldName, Object val)