Here you can find the source of getMethodOnlyByName(Class> c, String methodName)
Parameter | Description |
---|---|
c | Class to search |
methodName | Methodname to search |
Parameter | Description |
---|---|
NoSuchMethodException | If the search method isn't shown |
public static Method getMethodOnlyByName(Class<?> c, String methodName) throws NoSuchMethodException
//package com.java2s; // SMSLib is distributed under the terms of the Apache License version 2.0 import java.lang.reflect.Method; public class Main { /**// www . jav a 2 s .com * Searches in the given class for the given method name. The argument list * is ignored. Overload methods shouldn't used with it - You can't be sure * which method you will get! * * @param c * Class to search * @param methodName * Methodname to search * @return The found method * @throws NoSuchMethodException * If the search method isn't shown */ public static Method getMethodOnlyByName(Class<?> c, String methodName) throws NoSuchMethodException { Method method = null; for (Method m : c.getMethods()) { if (m.getName().equals(methodName)) { method = m; break; } } if (method == null) { throw new NoSuchMethodException(methodName); } return method; } }