static final Map callOpt_cache = newDangerousWeakHashMap(); static O callOpt_cached(O o, S methodName, O... args) ctex { if (o == null) null; _MethodCache cache; if (o instanceof Class) { Class c = (Class) o; synchronized(callOpt_cache) { cache = callOpt_cache.get(c); if (cache == null) cache = _MethodCache(c); } // TODO: (super-rare) case where method exists static and non-static // with different args Method me = cache.findMethod(methodName, args); if (me == null || (me.getModifiers() && Modifier.STATIC) == 0) null; ret invokeMethod(me, null, args); } else { Class c = o.getClass(); synchronized(callOpt_cache) { cache = callOpt_cache.get(c); if (cache == null) cache = _MethodCache(c); } Method me = cache.findMethod(methodName, args); if (me == null) null; ret invokeMethod(me, o, args); } }