Java Reflection Field Set setField(Class cl, String name, Object obj, Object value)

Here you can find the source of setField(Class cl, String name, Object obj, Object value)

Description

set Field

License

Open Source License

Declaration

public static void setField(Class<?> cl, String name, Object obj, Object value)
            throws ReflectiveOperationException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.lang.reflect.Field;

public class Main {
    public static void setField(Class<?> cl, String name, Object obj, Object value)
            throws ReflectiveOperationException {
        Field field = cl.getDeclaredField(name);
        field.setAccessible(true);// w  ww.j  a v  a  2 s  . c  o m
        field.set(obj, value);
    }
}

Related

  1. setField(Class cls, Object obj, String fieldName, Object value)
  2. setField(Class type, String name, Object instance, Object value)
  3. setField(Class klazz, Object recipient, String fieldName, Object newValue)
  4. setField(Class clazz, String fieldName, T instance, Object value)
  5. setField(Class c, Object inst, String name, Object value)
  6. setField(Class clazz, Object instance, String field, Object value)
  7. setField(Class clazz, Object obj, String fieldName, Object value)
  8. setField(Class ownerClass, Object owner, String fieldName, Object newValue)
  9. setField(Class target, Class fieldType, int index, Object obj, Object value)