public static Method getMostSpecificMethod(Method method, Class<?> targetClass) {
        if (targetClass != null && targetClass != method.getDeclaringClass() && isOverridable(method, targetClass)) {
            try {
                if (Modifier.isPublic(method.getModifiers())) {
                    try {
                        return targetClass.getMethod(method.getName(), method.getParameterTypes());
                    } catch (NoSuchMethodException ex) {
                        return method;
                    }
                } else {
                    return method;
                }
            } catch (SecurityException ex) {
                // Security settings are disallowing reflective access; fall back to 'method' below.
            }
        }
        return method;
    }
@Test
    public void testGetMostSpecificPublicMethod() throws NoSuchMethodException {
        Method method = Map.class.getDeclaredMethod("remove", Object.class, Object.class);
        Method specificMethod = ClassUtils.getMostSpecificMethod(method, HashMap.class);
        assertEquals(HashMap.class.getDeclaredMethod("remove", Object.class, Object.class), specificMethod);
    }