//package com.nowjava;
import java.lang.reflect.Method;/**from N o w J a v a . c o m - 时 代 Java**/
import java.util.List;
public class Main {
public static void main(String[] argv) throws Exception {
Class clazz = String.class;
List types = java.util.Arrays.asList("asdf", "nowjava.com");
String methodName = "nowjava.com";
System.out.println(findProperMethod(clazz, types, methodName));
}
public static Method findProperMethod(Class<?> clazz,
List<Class<?>> types, String methodName) {
Method[] methods = clazz.getMethods();/** 时代Java - N o w J a v a . c o m 提供 **/
for (Method method : methods) {
if (methodName.equals(method.getName())
&& isProperMethod(method, types)) {
return method;
}
}
return null;
}
protected static boolean isProperMethod(Method method,
List<Class<?>> types) {
Class<?>[] methodParams = method.getParameterTypes();
if (methodParams.length != types.size()) {
return false;
}
/**代码未完, 请加载全部代码(NowJava.com).**/
本文系作者在时代Java发表,未经许可,不得转载。如有侵权,请联系nowjava@qq.com删除。