Java Reflection Field Value Set setFieldValue(final Field field, final Object obj, final Object value)

Here you can find the source of setFieldValue(final Field field, final Object obj, final Object value)

Description

set Field Value

License

Open Source License

Declaration

private static void setFieldValue(final Field field, final Object obj, final Object value) 

Method Source Code


//package com.java2s;
/*/*  w w  w .j  a va2  s  .c o m*/
 * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */

import java.lang.reflect.Field;

public class Main {
    private static void setFieldValue(final Field field, final Object obj, final Object value) {
        try {
            field.set(obj, value);
        } catch (IllegalAccessException e) {
            throw new IllegalStateException(String.format("Failed to set field %s to %s", field, value), e);
        }
    }
}

Related

  1. setFieldValue(Field field, Object target, Object value)
  2. setFieldValue(Field field, Object value, Object instance)
  3. setFieldValue(Field field, Object value, Object target)
  4. setFieldValue(final Class clazz, final String fieldName, final Object fieldValue)
  5. setFieldValue(final Field field, final Object instance, final Object value)
  6. setFieldValue(final Field field, final Object value, final Object object)
  7. setFieldValue(final Object bean, final Field field, final Object value)
  8. setFieldValue(final Object obj, final String fieldName, final Object value)
  9. setFieldValue(final Object object, final String field, final Object value)