Java tutorial
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Method; public class Main { public static Method getMethod(Object o, String methodName, Class<?> returnType, Class<?>... parameters) { for (Method method : o.getClass().getDeclaredMethods()) { if (!method.getName().equals(methodName) || method.getReturnType() != returnType) continue; Class<?>[] pars = method.getParameterTypes(); if (parameters.length != pars.length) continue; boolean found = true; for (int i = 0; i < parameters.length; i++) { if (pars[i] != parameters[i]) { found = false; break; } } if (found) { return method; } } return null; } public static Method getMethod(Object o, String methodName, String returnType, Class<?>... parameters) { for (Method method : o.getClass().getDeclaredMethods()) { if (!method.getName().equals(methodName) || !method.getReturnType().getName().equals(returnType)) continue; Class<?>[] pars = method.getParameterTypes(); if (parameters.length != pars.length) continue; boolean found = true; for (int i = 0; i < parameters.length; i++) { if (pars[i] != parameters[i]) { found = false; break; } } if (found) { return method; } } return null; } public static Method getMethod(Object o, String methodName, String returnType, String... parameters) { for (Method method : o.getClass().getDeclaredMethods()) { if (!method.getName().equals(methodName) || !method.getReturnType().getName().equals(returnType)) continue; Class<?>[] pars = method.getParameterTypes(); if (parameters.length != pars.length) continue; boolean found = true; for (int i = 0; i < parameters.length; i++) { if (!pars[i].getName().equals(parameters[i])) { found = false; break; } } if (found) { return method; } } return null; } }