static Map> callOpt_noArgs_cache = newDangerousWeakHashMap(); static O callOpt_noArgs(O o, S method) ctex { if (o == null) ret null; if (o instanceof Class) ret callOpt(o, method); // not optimized Class c = o.getClass(); HashMap map; synchronized(callOpt_noArgs_cache) { map = callOpt_noArgs_cache.get(c); if (map == null) map = callOpt_noArgs_makeCache(c); } Method m = map.get(method); ret m != null ? m.invoke(o) : null; } // used internally - we are in synchronized block static HashMap callOpt_noArgs_makeCache(Class c) { new HashMap map; Class _c = c; do { for (Method m : c.getDeclaredMethods()) if (m.getParameterTypes().length == 0 && !reflection_isForbiddenMethod(m)) { makeAccessible(m); S name = m.getName(); if (!map.containsKey(name)) map.put(name, m); } _c = _c.getSuperclass(); } while (_c != null); callOpt_noArgs_cache.put(c, map); ret map; }