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 android.text.TextUtils;

import java.lang.reflect.Method;
import java.util.ArrayList;

public class Main {
    public static void invokeMethod(String paramString, Object paramObject, Object[] paramArrayOfObject)
            throws Exception {
        if (TextUtils.isEmpty(paramString))
            throw new RuntimeException("method name can not be empty");
        if (paramObject == null)
            throw new RuntimeException("target object can not be null");
        ArrayList localArrayList = new ArrayList();
        int i = paramArrayOfObject.length;
        for (int j = 0; j < i; j++)
            localArrayList.add(paramArrayOfObject[j].getClass());
        Method localMethod = paramObject.getClass().getDeclaredMethod(paramString,
                (Class[]) localArrayList.toArray());
        if (localMethod == null)
            throw new RuntimeException(
                    "target object: " + paramObject.getClass().getName() + " do not have this method: "
                            + paramString + " with parameters: " + localArrayList.toString());
        localMethod.setAccessible(true);
        localMethod.invoke(paramObject, paramArrayOfObject);
    }
}