Java Reflection Field Set setField(final Field field, final Object instance, final Object value)

Here you can find the source of setField(final Field field, final Object instance, final Object value)

Description

set Field

License

Open Source License

Declaration

public static void setField(final Field field, final Object instance, final 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 setField(final Field field, final Object instance, final Object value) {
        if (field == null) {
            throw new RuntimeException("No such field");
        }//from w w w.ja v a2s. c om
        field.setAccessible(true);
        try {
            field.set(instance, value);
        } catch (final Exception ex) {
            throw new RuntimeException(ex);
        }
    }
}

Related

  1. setField(Field field, Object target, Object value)
  2. setField(Field field, Object target, Object value)
  3. setField(Field field, Object target, Object value)
  4. setField(Field field, T newValue, Object instance)
  5. setField(Field field, U instance, Object value)
  6. setField(final Field field, final Object object, final Object value)
  7. setField(final O object, final String fieldName, final V value)
  8. setField(final Object instance, final String fieldName, final T value)
  9. setField(final Object obj, final String fieldName, final int value)