invoke Boolean Method via reflection - Android java.lang.reflect

Android examples for java.lang.reflect:Method Invoke

Description

invoke Boolean Method via reflection

Demo Code


//package com.java2s;

import java.lang.reflect.Method;

public class Main {
    static boolean invokeBooleanMethod(Object receiver,
            String className, String methodName, Object... args) {

        try {/*from   w w  w.  j  a  va  2s .c o  m*/
            Method method = Class.forName(className).getDeclaredMethod(
                    methodName);
            method.setAccessible(true);
            return (boolean) method.invoke(receiver, args);
        } catch (Throwable t) {
            t.printStackTrace();
        }

        return false;
    }
}

Related Tutorials