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 {

    public static Object invokeMethod(Object handler, String callback, Class<?>[] cls, Object... params) {

        if (handler == null || callback == null)
            return null;

        Method method = null;

        try {
            if (cls == null)
                cls = new Class[0];
            method = handler.getClass().getMethod(callback, cls);
            return method.invoke(handler, params);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }

        return null;

    }
}