static Object call(Class c, String method, Object... args) ctex { Method m = call_findStaticMethod(c, method, args); m.setAccessible(true); return m.invoke(null, args); } static Object call(Object o, String method, Object... args) ctex { Method m = call_findMethod(o, method, args); m.setAccessible(true); return m.invoke(o, args); } static Method call_findMethod(Object o, String method, Object[] args) { // TODO: go to superclasses too for (Method m : o.getClass().getDeclaredMethods()) if (m.getName().equals(method) && (m.getModifiers() & Modifier.STATIC) == 0 && m.getParameterTypes().length == args.length) // TODO: multicast return m; throw new RuntimeException("Method '" + method + "' with " + args.length + " parameter(s) not found in " + o.getClass().getName()); } static Method call_findStaticMethod(Class c, String method, Object[] args) { for (Method m : c.getDeclaredMethods()) if (m.getName().equals(method) && (m.getModifiers() & Modifier.STATIC) != 0 && m.getParameterTypes().length == args.length) // TODO: multicast return m; throw new RuntimeException("Static method '" + method + "' with " + args.length + " parameter(s) not found in " + c.getName()); }