static int numberOfMethodArguments(O o, S method) { Class c; bool mustBeStatic = false; if (o instanceof Class) { c = (Class) o; mustBeStatic = true; } else c = o.getClass(); Class _c = c; int n = -1; while (c != null) { for (Method m : c.getDeclaredMethods()) { if (!m.getName().equals(method)) continue; if (mustBeStatic && !methodIsStatic(m)) continue; int nn = l(m.getParameterTypes()); if (n == -1) n = nn; else if (n != nn) fail("Variable number of method arguments: " + _c + "." + method); } c = c.getSuperclass(); } if (n == -1) fail("Method not found: " + _c + "." + method); ret n; }