Here you can find the source of invokeSetter(Method setter, Object object, Object propValue)
Parameter | Description |
---|---|
setter | a parameter |
object | a parameter |
propValue | a parameter |
public static void invokeSetter(Method setter, Object object, Object propValue)
//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); } } }