Java Reflection Field Set setField(Object object, String field, Object value)

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

Description

set Field

License

Apache License

Declaration

public static void setField(Object object, String field, Object value) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.lang.reflect.Field;

public class Main {
    public static void setField(Object object, String field, Object value) {
        if (object == null || field == null)
            return;

        try {//from  www  .  j a v a  2  s .  c o m
            Field target = object.getClass().getDeclaredField(field);
            target.setAccessible(true);
            target.set(object, value);
        } catch (Exception ignored) {
        }
    }
}

Related

  1. setField(Object object, Class clazz, String fieldName, Object value)
  2. setField(Object object, Class clazz, String fieldName, Object value)
  3. setField(Object object, Field field, Object value)
  4. setField(Object object, Field field, Object value)
  5. setField(Object object, Object value, String name)
  6. setField(Object object, String fieldName, int value)
  7. setField(Object object, String fieldName, Object newValue)
  8. setField(Object object, String fieldName, Object newValue, boolean isFindDeclaredField, boolean isUpwardFind)
  9. setField(Object object, String fieldName, Object value)