Java tutorial
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Method; public class Main { public static Method findMethodByNameAndReturnType(Class<?> targetObject, String methodName, String returnType, Class<?>... params) { for (Method method : targetObject.getDeclaredMethods()) { if (method.getReturnType().getName().equals(returnType) && method.getName().equals(methodName)) { Class[] parameterTypes = method.getParameterTypes(); if (params.length != parameterTypes.length) { continue; } for (int i = 0; i < params.length; i++) { if (params[i] != parameterTypes[i]) { break; } } method.setAccessible(true); return method; } } throw new NoSuchMethodError(); } }