Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

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

public class Main {
    /**
     * 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);
        }
    }
}