Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.util.Log;

import java.lang.reflect.Method;

public class Main {
    private final static String TAG = "ReflectHelper";

    public static void invokeObjMethod(Object ob, String methodName, int value1, int value2) {

        if (ob == null) {
            return;
        }
        try {
            Method method = ob.getClass().getMethod(methodName, int.class, int.class);
            method.invoke(ob, value1, value2);
        } catch (Exception e) {
            Log.d(TAG, "invokeObjMethod error", e);
        }
    }

    public static void invokeObjMethod(Object ob, String methodName, CharSequence value) {

        if (ob == null) {
            return;
        }
        try {
            Method method = ob.getClass().getMethod(methodName, CharSequence.class);
            method.invoke(ob, value);
        } catch (Exception e) {
            Log.d(TAG, "invokeObjMethod error", e);
        }
    }

    public static void invokeObjMethod(Object ob, String methodName, Runnable value) {

        if (ob == null) {
            return;
        }
        try {
            Method method = ob.getClass().getMethod(methodName, Runnable.class);
            method.invoke(ob, value);
        } catch (Exception e) {
            Log.d(TAG, "invokeObjMethod error", e);
        }
    }
}