Util { public static Method getMostSpecificMethod(Method method1, Method method2) { Class<?> class1 = method1.getParameterTypes()[0]; Class<?> class2 = method2.getParameterTypes()[0]; if (class1.isAssignableFrom(class2)) { return method2; } else { return method1; } } private  Util(); static boolean isInstance(Class type, Object instance); static void addProperty(Hashtable env, String property); static Method findSetter(Class<?> testClazz, Field field, Object propertyValue); static Method getMostSpecificMethod(Method method1, Method method2);  }
@Test public void testGetMostSpecificMethod() throws Exception { Method mObject = getClass().getDeclaredMethod("setThreeAccessibleNoExactMatchSetter", Object.class); Method mThrowable = getClass().getDeclaredMethod("setThreeAccessibleNoExactMatchSetter", Throwable.class); Method mException = getClass().getDeclaredMethod("setThreeAccessibleNoExactMatchSetter", Exception.class); assertEquals(mThrowable, Util.getMostSpecificMethod(mObject, mThrowable)); assertEquals(mException, Util.getMostSpecificMethod(mException, mThrowable)); assertEquals(mException, Util.getMostSpecificMethod(mException, mObject)); }