code: public <T> void registerRefListener(T oldObject, final Listener<T> listener) {
      checkNotNull(oldObject);
      checkNotNull(listener);
      Object oldMapping = mappings.get(oldObject);
      if (oldMapping == null) {
        // store the listener so it will be run when the old object mapping is registered
        mappings.put(oldObject, listener);
      } else if (oldMapping instanceof Listener) {
        // chain the listeners
        @SuppressWarnings("unchecked") // Listener<T> can only be registered with a T
        final Listener<T> oldListener = (Listener) oldMapping;
        mappings.put(oldObject, chainListeners(listener, oldListener));
      } else {
        // if there was a value mapped to the old object it must have been a T
        @SuppressWarnings("unchecked")
        T typedValue = (T) oldMapping;
        listener.newVersion(typedValue);
      }
    }
docs: Registers a listener to be invoked if the given object is ever updated via the {@link
  #updateRefs} method.
  
  <p>Note: the listener may be executed inline or not at all.