static WeakHashMap> callF_cache = new WeakHashMap; ifclass F0 static A callF(F0 f) { ret f == null ? null : f.get(); } endif ifclass F1 static B callF(F1 f, A a) { ret f == null ? null : f.get(a); } endif static O callF(O f, O... args) ctex { if (f instanceof S) ret callMC((S) f, args); if (f instanceof Runnable) { ((Runnable) f).run(); null; } if (f == null) ret null; Class c = f.getClass(); ArrayList methods; synchronized(callF_cache) { methods = callF_cache.get(c); if (methods == null) methods = callF_makeCache(c); } int n = l(methods); if (n == 0) { if (c instanceof DynamicCallable) ret c/DynamicCallable.get(args); fail("No get method in " + getClassName(c)); } if (n == 1) ret invokeMethod(methods.get(0), f, args); for i to n: { Method m = methods.get(i); if (call_checkArgs(m, args, false)) ret invokeMethod(m, f, args); } fail("No matching get method in " + getClassName(c)); } // used internally static ArrayList callF_makeCache(Class c) { new ArrayList l; Class _c = c; do { for (Method m : _c.getDeclaredMethods()) if (m.getName().equals("get")) { m.setAccessible(true); l.add(m); } if (!l.isEmpty()) break; _c = _c.getSuperclass(); } while (_c != null); callF_cache.put(c, l); ret l; }