static HashMap> callMC_cache = new HashMap; static S callMC_key; static Method callMC_value; // varargs assignment fixer for a single string array argument static Object callMC(S method, S[] arg) { ret callMC(method, new O[] {arg}); } static O callMC(S method, O... args) ctex { Method me; if (callMC_cache == null) callMC_cache = new HashMap; // initializer time workaround synchronized(callMC_cache) { me = method == callMC_key ? callMC_value : null; } if (me != null) try { ret invokeMethod(me, null, args); } catch (IllegalArgumentException e) { throw new RuntimeException("Can't call " + me + " with arguments " + classNames(args), e); } L m; synchronized(callMC_cache) { m = callMC_cache.get(method); } if (m == null) { if (callMC_cache.isEmpty()) { callMC_makeCache(); m = callMC_cache.get(method); } if (m == null) fail("Method named " + method + " not found in main"); } int n = m.size(); if (n == 1) { me = m.get(0); synchronized(callMC_cache) { callMC_key = method; callMC_value = me; } try { ret invokeMethod(me, null, args); } catch (IllegalArgumentException e) { throw new RuntimeException("Can't call " + me + " with arguments " + classNames(args), e); } } for i to n: { me = m.get(i); if (call_checkArgs(me, args, false)) ret invokeMethod(me, null, args); } fail("No method called " + method + " with arguments (" + joinWithComma(getClasses(args)) + ") found in main"); } static void callMC_makeCache() { synchronized(callMC_cache) { callMC_cache.clear(); Class _c = (Class) mc(), c = _c; while (c != null) { for (Method m : c.getDeclaredMethods()) if ((m.getModifiers() & java.lang.reflect.Modifier.STATIC) != 0) { makeAccessible(m); multiMapPut(callMC_cache, m.getName(), m); } c = c.getSuperclass(); } } }