code: public static <T> T createInstance(Class<T> type, Object... parameters) {
  
      // get types for parameters
      Class<?>[] parameterTypes = new Class<?>[parameters.length];
      for (int i = 0; i < parameters.length; i++) {
        Object parameter = parameters[i];
        parameterTypes[i] = parameter.getClass();
      }
  
      try {
        // create instance
        Constructor<T> constructor = type.getConstructor(parameterTypes);
        return constructor.newInstance(parameters);
  
      } catch (Exception e) {
        throw new ModelException("Exception while creating an instance of type "+type, e);
      }
    }
docs: Create a new instance of the provided type
  
  @param type the class to create a new instance of
  @param parameters the parameters to pass to the constructor
  @return the created instance