Java Reflection Field Set setField(Object source, String fieldName, Object value)

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

Description

set Field

License

Open Source License

Declaration

public static void setField(Object source, String fieldName, Object value) throws Exception 

Method Source Code


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

import java.lang.reflect.Field;

public class Main {
    public static void setField(Object source, String fieldName, Object value) throws Exception {
        Class cl = source.getClass();

        Field f = cl.getDeclaredField(fieldName);
        f.setAccessible(true);//from   ww  w  .  j av a2 s. c om

        f.set(source, value);

    }
}

Related

  1. setField(Object object, String name, Object value)
  2. setField(Object object, String name, Object value)
  3. setField(Object owner, String name, Object newValue, Class definedIn)
  4. setField(Object owner, String targetClass, String fieldName, Object value)
  5. setField(Object service, String name, Object obj)
  6. setField(Object sourceObj, Object targetObj, Field valueField, List targetFields)
  7. setField(Object target, Field field, Object value)
  8. setField(Object target, Field field, Object value)
  9. setField(Object target, String fieldName, Class fieldType, T value)