invoke a method on instance object - Android java.lang.reflect

Android examples for java.lang.reflect:Method Invoke

Description

invoke a method on instance object

Demo Code

/*******************************************************************************
 * Copyright (c) 2011 MadRobot./*from  w ww .j  av  a 2 s .  co  m*/
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Contributors:
 *  Elton Kent - initial API and implementation
 ******************************************************************************/
//package com.java2s;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Main {
    private static Object invoke(Method method, Object instance,
            Object... args) {
        try {
            return method.invoke(instance, args);
        } catch (IllegalAccessException e) {
            return null;
        } catch (InvocationTargetException e) {
            return null;
        } catch (RuntimeException re) {
            return null;
        }
    }
}

Related Tutorials