@Test public void testFindMethodByArglistVararg() throws Exception { ReflectionTestFunctionLibrary library = new ReflectionTestFunctionLibrary(); List<Object> argList = new ArrayList<Object>(); argList.add("foo"); argList.add("bar"); argList.add("baz"); Method method = ReflectionUtil.findMethod(library, "v", argList); assertNotNull("No method", method); method.invoke(library, new Object[] { new String[] {"foo", "bar", "baz"}}); assertCalled(library, "v:3"); }
public static Method findMethod(Object object, String methodName, int arity) { for (Method method: object.getClass().getMethods()) { if (method.getName().equals(methodName) && method.getParameterTypes().length == arity && !method.isVarArgs()) { return method; } } return null; }
ReflectionUtil { public static Method findMethod(Object object, String methodName, int arity) { for (Method method: object.getClass().getMethods()) { if (method.getName().equals(methodName) && method.getParameterTypes().length == arity && !method.isVarArgs()) { return method; } } return null; } }
ReflectionUtil { public static Method findMethod(Object object, String methodName, int arity) { for (Method method: object.getClass().getMethods()) { if (method.getName().equals(methodName) && method.getParameterTypes().length == arity && !method.isVarArgs()) { return method; } } return null; }  }
ReflectionUtil { public static Method findMethod(Object object, String methodName, int arity) { for (Method method: object.getClass().getMethods()) { if (method.getName().equals(methodName) && method.getParameterTypes().length == arity && !method.isVarArgs()) { return method; } } return null; }  static T getJavaProperty(Object object, String propertyName, Class<T> propetyClass); static boolean hasJavaProperty(Object object, String propertyName); static Method findGetter(Object object, String propertyName); static Method findMethod(Object object, String methodName, int arity); static Method findMethod(Object object, String methodName, List<?> argList); static Method findVarArgsMethod(Object object, String methodName); static Object invokeMethod(Object object, String methodName, List<?> argList); static String debugDumpArgList(List<?> argList); }
ReflectionUtil { public static Method findMethod(Object object, String methodName, int arity) { for (Method method: object.getClass().getMethods()) { if (method.getName().equals(methodName) && method.getParameterTypes().length == arity && !method.isVarArgs()) { return method; } } return null; }  static T getJavaProperty(Object object, String propertyName, Class<T> propetyClass); static boolean hasJavaProperty(Object object, String propertyName); static Method findGetter(Object object, String propertyName); static Method findMethod(Object object, String methodName, int arity); static Method findMethod(Object object, String methodName, List<?> argList); static Method findVarArgsMethod(Object object, String methodName); static Object invokeMethod(Object object, String methodName, List<?> argList); static String debugDumpArgList(List<?> argList);  }