private static <T> T doGetObjWithArgs(String className, Class<T> clazz, ConstructorArgument<?>... args) {
    Validate.notNull(className, "Null class name");

    try {
      //noinspection unchecked
      Class<T> classObj = (Class<T>) Class.forName(className);
      if (args.length == 0) {
        return classObj.newInstance();
      } else {
        // can't just use getClass on argument values since runtime types might not exactly match constructor signatures
        Class<?>[] argClasses = new Class<?>[args.length];
        Object[] argValues = new Object[args.length];
        IntStream.range(0, args.length).forEach(i -> {
          ConstructorArgument<?> constructorArgument = args[i];
          argClasses[i] = constructorArgument.getClazz();
          argValues[i] = constructorArgument.getValue();
        });
        Constructor<T> constructor = classObj.getDeclaredConstructor(argClasses);
        return constructor.newInstance(argValues);
      }
    } catch (Exception e) {
      String errorMessage = String.format("Unable to create instance for class: %s", className);
      LOG.error(errorMessage, e);
      throw new SamzaException(errorMessage, e);
    }
  }
Create an instance of the specified class with constructor matching the argument array. If there are no args, then
this will use the empty constructor. Make sure that the types passed using {@link ConstructorArgument} match the
compile-time types of the arguments of the constructor that should be used.

@param <T> type of the object to return
@param className name of the class
@param clazz type of object to return
@param args arguments with types for finding and calling desired constructor to create an instance of className
@return instance of the class
@throws SamzaException if an exception was thrown while trying to create the class
samza-core/src/main/java/org/apache/samza/util/ReflectionUtil.java