Java Reflection Field Set setField(Object obj, String fieldname, Object value)

Here you can find the source of setField(Object obj, String fieldname, Object value)

Description

set Field

License

Open Source License

Parameter

Parameter Description
obj a parameter
fieldname a parameter
value a parameter

Declaration

public static void setField(Object obj, String fieldname, Object value) 

Method Source Code

//package com.java2s;

import java.lang.reflect.Field;

public class Main {
    /**/*from  w  w  w.  j a v  a2 s  .  co m*/
     * 
     * @param obj
     * @param fieldname
     * @param value
     */
    public static void setField(Object obj, String fieldname, Object value) {
        try {
            Field field = obj.getClass().getField(fieldname);
            field.setAccessible(true);
            field.set(obj, value);
        } catch (Exception e) {
            // ignore
        }
    }
}

Related

  1. setField(Object obj, Field field, Object value)
  2. setField(Object obj, Object value, String fieldName)
  3. setField(Object obj, Object value, String fieldName)
  4. setField(Object obj, String fieldName, Object fieldValue)
  5. setField(Object obj, String fieldName, Object val)
  6. setField(Object obj, String fieldName, Object value)
  7. setField(Object obj, String fieldName, Object value)
  8. setField(Object obj, String fieldName, Object value, Class valueClass)
  9. setField(Object obj, String name, Object value)