@Test public void testResolveMethod10() throws ClassNotFoundException, NoSuchMethodException { Class< ? > declareClass = Class.forName("java.lang.String"); String methodName = "valueOf"; Class< ? >[] paramTypes = new Class< ? >[] {String.class}; Method actualMethod = MethodResolver.resolveMethod(declareClass, methodName, paramTypes); Method expectedMethod = declareClass.getMethod(methodName, Object.class); Assert.assertEquals(expectedMethod, actualMethod); }
public static Method resolveMethod(Class< ? > declareClass, String methodName, Class< ? >[] paramTypes) { Method[] declaredMethods = declareClass.getDeclaredMethods(); Method bestMatchMethod = null; int bestConversionCount = -1; for (Method method : declaredMethods) { if (!isPublic(method)) { continue; } if (!method.getName().equals(methodName)) { continue; } int conversionCount = compareParamTypes(method.getParameterTypes(), paramTypes); if (conversionCount == -1) { continue; } if (conversionCount == 0) { bestMatchMethod = method; break; } if (null == bestMatchMethod) { bestMatchMethod = method; bestConversionCount = conversionCount; } else { if (conversionCount < bestConversionCount) { bestMatchMethod = method; bestConversionCount = conversionCount; } } } return bestMatchMethod; }
MethodResolver { public static Method resolveMethod(Class< ? > declareClass, String methodName, Class< ? >[] paramTypes) { Method[] declaredMethods = declareClass.getDeclaredMethods(); Method bestMatchMethod = null; int bestConversionCount = -1; for (Method method : declaredMethods) { if (!isPublic(method)) { continue; } if (!method.getName().equals(methodName)) { continue; } int conversionCount = compareParamTypes(method.getParameterTypes(), paramTypes); if (conversionCount == -1) { continue; } if (conversionCount == 0) { bestMatchMethod = method; break; } if (null == bestMatchMethod) { bestMatchMethod = method; bestConversionCount = conversionCount; } else { if (conversionCount < bestConversionCount) { bestMatchMethod = method; bestConversionCount = conversionCount; } } } return bestMatchMethod; } }
MethodResolver { public static Method resolveMethod(Class< ? > declareClass, String methodName, Class< ? >[] paramTypes) { Method[] declaredMethods = declareClass.getDeclaredMethods(); Method bestMatchMethod = null; int bestConversionCount = -1; for (Method method : declaredMethods) { if (!isPublic(method)) { continue; } if (!method.getName().equals(methodName)) { continue; } int conversionCount = compareParamTypes(method.getParameterTypes(), paramTypes); if (conversionCount == -1) { continue; } if (conversionCount == 0) { bestMatchMethod = method; break; } if (null == bestMatchMethod) { bestMatchMethod = method; bestConversionCount = conversionCount; } else { if (conversionCount < bestConversionCount) { bestMatchMethod = method; bestConversionCount = conversionCount; } } } return bestMatchMethod; }  }
MethodResolver { public static Method resolveMethod(Class< ? > declareClass, String methodName, Class< ? >[] paramTypes) { Method[] declaredMethods = declareClass.getDeclaredMethods(); Method bestMatchMethod = null; int bestConversionCount = -1; for (Method method : declaredMethods) { if (!isPublic(method)) { continue; } if (!method.getName().equals(methodName)) { continue; } int conversionCount = compareParamTypes(method.getParameterTypes(), paramTypes); if (conversionCount == -1) { continue; } if (conversionCount == 0) { bestMatchMethod = method; break; } if (null == bestMatchMethod) { bestMatchMethod = method; bestConversionCount = conversionCount; } else { if (conversionCount < bestConversionCount) { bestMatchMethod = method; bestConversionCount = conversionCount; } } } return bestMatchMethod; }  static Method resolveMethod(Class< ? > declareClass, String methodName, Class< ? >[] paramTypes); }
MethodResolver { public static Method resolveMethod(Class< ? > declareClass, String methodName, Class< ? >[] paramTypes) { Method[] declaredMethods = declareClass.getDeclaredMethods(); Method bestMatchMethod = null; int bestConversionCount = -1; for (Method method : declaredMethods) { if (!isPublic(method)) { continue; } if (!method.getName().equals(methodName)) { continue; } int conversionCount = compareParamTypes(method.getParameterTypes(), paramTypes); if (conversionCount == -1) { continue; } if (conversionCount == 0) { bestMatchMethod = method; break; } if (null == bestMatchMethod) { bestMatchMethod = method; bestConversionCount = conversionCount; } else { if (conversionCount < bestConversionCount) { bestMatchMethod = method; bestConversionCount = conversionCount; } } } return bestMatchMethod; }  static Method resolveMethod(Class< ? > declareClass, String methodName, Class< ? >[] paramTypes);  }