static Map> callF_cache = newDangerousWeakHashMap(); 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 ifclass IF0 static A callF(IF0 f) { ret f == null ? null : f.get(); } endif ifclass IF1 static B callF(IF1 f, A a) { ret f == null ? null : f.get(a); } endif static B callF(A a, IF1 f) { ret f == null ?: f.get(a); } ifclass F2 static C callF(F2 f, A a, B b) { ret f == null ? null : f.get(a, b); } endif ifclass IF2 static C callF(IF2 f, A a, B b) { ret f == null ? null : f.get(a, b); } endif ifclass VF1 static void callF(VF1 f, A a) { if (f != null) f.get(a); } endif static void callF(A a, IVF1 f) { if (f != null) f.get(a); } static void callF(IVF1 f, A a) { if (f != null) f.get(a); } sO callF(Runnable r) { r?.run(); null; } sO callF(O f, O... args) { ifdef callF_legacy if (f instanceof S) // no way josé ret callMCWithVarArgs((S) f, args); endifdef ret safeCallF(f, args); } sO safeCallF(O f, O... args) { if (f instanceof Runnable) { ((Runnable) f).run(); null; } if (f == null) 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) { ifclass DynamicCallable if (f instanceof DynamicCallable) ret f/DynamicCallable._dyn(args); endif ifndef callF_legacy if (f instanceof S) fail("Legacy call: " + f); endifndef 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")) { makeAccessible(m); l.add(m); } if (!l.isEmpty()) break; _c = _c.getSuperclass(); } while (_c != null); callF_cache.put(c, l); ret l; }