/** * Extracts a method matching the source method, allowing generic type parameters to be substituted as * long as they are properly castable. * * @param clazz The target class * @param sourceMethod The source method. * @return the extracted method or <code>null</code> */ public static Method extractPossiblyGenericMethod(Class<?> clazz, Method sourceMethod) { Method exactMethod = extractMethod(clazz, sourceMethod); if (exactMethod == null) { String methodName = sourceMethod.getName(); Class<?>[] parameterTypes = sourceMethod.getParameterTypes(); for (Method method : clazz.getMethods()) { if (method.getName().equals(methodName) && allSameType(method.getParameterTypes(), parameterTypes)) { return method; } } return null; } else { return exactMethod; } }
/** * Extracts a method matching the source method, allowing generic type parameters to be substituted as * long as they are properly castable. * * @param clazz The target class * @param sourceMethod The source method. * @return the extracted method or <code>null</code> */ public static Method extractPossiblyGenericMethod(Class<?> clazz, Method sourceMethod) { Method exactMethod = extractMethod(clazz, sourceMethod); if (exactMethod == null) { String methodName = sourceMethod.getName(); Class<?>[] parameterTypes = sourceMethod.getParameterTypes(); for (Method method : clazz.getMethods()) { if (method.getName().equals(methodName) && allSameType(method.getParameterTypes(), parameterTypes)) { return method; } } return null; } else { return exactMethod; } }