Get Method from a Class<?> by method Name - Android java.lang.reflect

Android examples for java.lang.reflect:Class

Description

Get Method from a Class<?> by method Name

Demo Code

/*******************************************************************************
 * Copyright (c) 2011 MadRobot.//  w  w  w. 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.Method;

public class Main {
    private static Method maybeGetMethod(Class<?> clazz, String name,
            Class<?>... argClasses) {
        try {
            return clazz.getMethod(name, argClasses);
        } catch (NoSuchMethodException nsme) {
            // OK
            return null;
        } catch (RuntimeException re) {
            return null;
        }
    }
}

Related Tutorials