Java Reflection Field Set setField(Object instance, String sField, Object value)

Here you can find the source of setField(Object instance, String sField, Object value)

Description

set Field

License

Open Source License

Declaration

public static void setField(Object instance, String sField, Object value) throws SecurityException,
            NoSuchFieldException, ClassNotFoundException, IllegalArgumentException, IllegalAccessException 

Method Source Code

//package com.java2s;

import java.lang.reflect.Field;

public class Main {
    public static void setField(Object instance, String sField, Object value) throws SecurityException,
            NoSuchFieldException, ClassNotFoundException, IllegalArgumentException, IllegalAccessException {
        Field field = instance.getClass().getDeclaredField(sField);
        field.setAccessible(true);/*  ww w  . ja v a  2s. c om*/
        field.set(instance, value);
    }
}

Related

  1. setField(final Object object, final String name, final Object value)
  2. setField(final Object parent, final String name, final Object obj)
  3. setField(java.lang.Object toObj, String tcFieldName, java.lang.Object toNewValue)
  4. setField(Object instance, String fieldName, Object value)
  5. setField(Object instance, String name, Object obj)
  6. setField(Object item, Field f, Object value)
  7. setField(Object o, String fieldName, Object inject)
  8. setField(Object o, String fieldName, Object value)
  9. setField(Object o, String fieldName, Object value)