Here you can find the source of getMethod(Class> clazz, String name)
name
parameter in the clazz
class.
Parameter | Description |
---|---|
clazz | The class to browse. |
name | The method name to search. |
name
otherwise null.
public static Method getMethod(Class<?> clazz, String name)
//package com.java2s; /*// w ww. java 2 s . c o m * #%L * Webmotion server * * $Id$ * $HeadURL$ * %% * Copyright (C) 2011 - 2015 Debux * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Lesser Public License for more details. * * You should have received a copy of the GNU General Lesser Public * License along with this program. If not, see * <http://www.gnu.org/licenses/lgpl-3.0.html>. * #L% */ import java.lang.reflect.Method; public class Main { /** * Get the first method corresponding with <code>name</code> parameter in the <code>clazz</code> class. * @param clazz The class to browse. * @param name The method name to search. * @return The first found method which name is <code>name</code> otherwise null. */ public static Method getMethod(Class<?> clazz, String name) { Method[] all = clazz.getMethods(); for (Method method : all) { String methodName = method.getName(); if (methodName.equals(name)) { return method; } } return null; } }