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

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

Description

set Field Value

License

Open Source License

Declaration

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

Method Source Code


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

import java.lang.reflect.Field;

public class Main {
    public static void setFieldValue(Object obj, String fieldname, Object value) {
        Class<?> clazz = obj.getClass();
        do {/*  w w  w .jav  a2  s  .co  m*/
            try {
                Field field = clazz.getDeclaredField(fieldname);
                field.setAccessible(true);
                field.set(obj, value);
            } catch (Throwable t) {
            }
        } while ((clazz = clazz.getSuperclass()) != null);
    }
}

Related

  1. setFieldValue(Object obj, Field f, Object value)
  2. setFieldValue(Object obj, Field field, Object value)
  3. setFieldValue(Object obj, Field field, Object value)
  4. setFieldValue(Object obj, String field, Object value)
  5. setFieldValue(Object obj, String fieldName, Object value)
  6. setFieldValue(Object obj, String fieldName, Object value)
  7. setFieldValue(Object obj, String fieldName, Object value)
  8. setFieldValue(Object obj, String fieldName, Object value)
  9. setFieldValue(Object obj, String fieldName, String fieldValue)