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

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

Description

set Field

License

LGPL

Declaration

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

Method Source Code

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

import java.lang.reflect.Field;

import java.lang.reflect.Modifier;

public class Main {
    public static void setField(Field field, Object target, Object value) {
        if (!Modifier.isPublic(field.getModifiers())) {
            field.setAccessible(true);//from  w w  w .  j a  va 2 s . c o  m
        }
        try {
            field.set(target, value);
        } catch (IllegalAccessException iae) {
            throw new IllegalArgumentException("Could not set field " + field, iae);
        }
    }
}

Related

  1. setField(Field field, Object instance, Object value)
  2. setField(Field field, Object obj, String value)
  3. setField(Field field, Object objToSet, Object value)
  4. setField(Field field, Object target, Object value)
  5. setField(Field field, Object target, Object value)
  6. setField(Field field, Object target, Object value)
  7. setField(Field field, Object target, Object value)
  8. setField(Field field, Object target, Object value)
  9. setField(Field field, Object target, Object value)