@Test public void find_VisitorB_VisitableFoo() { Class<?> clazz = VisitorB.class; Object param = new VisitableFoo(); Method m = ReflectionTools.findMethod(clazz, "visit", param); assertMethod(m, VisitorA.class, "visit", param.getClass()); }
public static Method findMethod(Class<?> clazz, String methodName, Object methodParam) { Method method = null; Class<?> methodParamClass = methodParam.getClass(); while (methodParamClass != null) { method = ReflectionUtils.findMethod(clazz, "visit", methodParamClass); if (method != null) { return method; } for (Class<?> interf : methodParamClass.getInterfaces()) { method = ReflectionUtils.findMethod(clazz, "visit", interf); if (method != null) { return method; } } methodParamClass = methodParamClass.getSuperclass(); } return null; }
ReflectionTools { public static Method findMethod(Class<?> clazz, String methodName, Object methodParam) { Method method = null; Class<?> methodParamClass = methodParam.getClass(); while (methodParamClass != null) { method = ReflectionUtils.findMethod(clazz, "visit", methodParamClass); if (method != null) { return method; } for (Class<?> interf : methodParamClass.getInterfaces()) { method = ReflectionUtils.findMethod(clazz, "visit", interf); if (method != null) { return method; } } methodParamClass = methodParamClass.getSuperclass(); } return null; } }
ReflectionTools { public static Method findMethod(Class<?> clazz, String methodName, Object methodParam) { Method method = null; Class<?> methodParamClass = methodParam.getClass(); while (methodParamClass != null) { method = ReflectionUtils.findMethod(clazz, "visit", methodParamClass); if (method != null) { return method; } for (Class<?> interf : methodParamClass.getInterfaces()) { method = ReflectionUtils.findMethod(clazz, "visit", interf); if (method != null) { return method; } } methodParamClass = methodParamClass.getSuperclass(); } return null; } private  ReflectionTools(); }
ReflectionTools { public static Method findMethod(Class<?> clazz, String methodName, Object methodParam) { Method method = null; Class<?> methodParamClass = methodParam.getClass(); while (methodParamClass != null) { method = ReflectionUtils.findMethod(clazz, "visit", methodParamClass); if (method != null) { return method; } for (Class<?> interf : methodParamClass.getInterfaces()) { method = ReflectionUtils.findMethod(clazz, "visit", interf); if (method != null) { return method; } } methodParamClass = methodParamClass.getSuperclass(); } return null; } private  ReflectionTools(); static Method findMethod(Class<?> clazz, String methodName, Object methodParam); }
ReflectionTools { public static Method findMethod(Class<?> clazz, String methodName, Object methodParam) { Method method = null; Class<?> methodParamClass = methodParam.getClass(); while (methodParamClass != null) { method = ReflectionUtils.findMethod(clazz, "visit", methodParamClass); if (method != null) { return method; } for (Class<?> interf : methodParamClass.getInterfaces()) { method = ReflectionUtils.findMethod(clazz, "visit", interf); if (method != null) { return method; } } methodParamClass = methodParamClass.getSuperclass(); } return null; } private  ReflectionTools(); static Method findMethod(Class<?> clazz, String methodName, Object methodParam);  }