code: public static <T> T instantiate(String type, Class<T> requiredType) {
          try {
              return ClassUtils.forName(type, requiredType.getClassLoader())
                  .flatMap((Function<Class, Optional<T>>) aClass -> {
                      if (requiredType == aClass || requiredType.isAssignableFrom(aClass)) {
                          return tryInstantiate(aClass);
                      }
                      return Optional.empty();
                  })
                  .orElseThrow(() -> new InstantiationException("No compatible class found for name: " + type));
          } catch (Throwable e) {
              throw new InstantiationException("Could not instantiate type [" + type + "]: " + e.getMessage(), e);
          }
      }
docs: Instantiate the given class rethrowing any exceptions as {@link InstantiationException}.
  
  @param type         The type
  @param requiredType The required type
  @param <T>          The type
  @return The instantiated instance
  @throws InstantiationException When an error occurs