Java Reflection Method Setter Invoke invokeSetter(Method setter, Object object, Object propValue)

Here you can find the source of invokeSetter(Method setter, Object object, Object propValue)

Description

invoke a setter method

License

Apache License

Parameter

Parameter Description
setter a parameter
object a parameter
propValue a parameter

Declaration

public static void invokeSetter(Method setter, Object object,
        Object propValue) 

Method Source Code

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

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Main {
    /**/*from w w w.  j  a  va 2  s .co m*/
     * invoke a setter method
     * 
     * @param setter
     * @param object
     * @param propValue
     */
    public static void invokeSetter(Method setter, Object object,
            Object propValue) {
        if (setter == null) {
            throw new IllegalArgumentException(
                    "The setter method cannot be null");
        }

        if (object == null) {
            throw new IllegalArgumentException("The object cannot be null");
        }

        try {
            setter.setAccessible(true);
            setter.invoke(object, new Object[] { propValue });
        } catch (IllegalAccessException e) {
            throw new IllegalStateException(e);
        } catch (InvocationTargetException e) {
            throw new IllegalStateException(e);
        }
    }
}

Related

  1. invokeSetter(final Method setter, final Object target, Object value)
  2. invokeSetter(Method setter, Object obj, String fieldName, Object value)
  3. invokeSetter(Method setter, Object obj, String value)
  4. invokeSetter(Object entity, String propertyName, Object propertyValue)
  5. invokeSetter(Object o, String name, Class value1clazz, Object value)
  6. invokeSetter(Object o, String name, Object value, Class clazz)
  7. invokeSetterMethod(Method method, Object oBean, Object oValue)