static O mapMethodLike vmBus_onMessage_weakRef(S msg, IVF1 onMessage) { Map map = vm_busListenersByMessage_live(); WeakRefVMBusListener listener = new((IVF2) (_msg, arg) -> onMessage.get(arg)); synchronized(map) { Set listeners = map.get(msg); if (listeners == null) map.put(msg, listeners = syncIdentityHashSet()); // We're technically violating the one-synchronized-object-per-thread rule, // but it should be OK here. // TODO: remove empty sets from map listeners.add(listener); } ret listener; }