code: private ReferenceFactory<?> createFactory(final Constructor<?> constructor) {
      return manager -> {
        try {
          return (ReferenceCounted<?>) constructor.newInstance(manager);
        } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
          throw new SerializationException("failed to instantiate reference", e);
        }
      };
    }
docs: Dynamically created a reference factory for a pooled type.