public static <T> T newInstance(Class<T> theClass, Class<?>[] parameterTypes,
                                  Object[] initargs) {
    // Perform some sanity checks on the arguments.
    if (parameterTypes.length != initargs.length) {
      throw new IllegalArgumentException(
          "Number of constructor parameter types doesn't match number of arguments");
    }
    for (int i = 0; i < parameterTypes.length; i++) {
      // initargs are boxed to Object, so we need to wrapper primitive types here.
      Class<?> clazz = ClassUtils.primitiveToWrapper(parameterTypes[i]);
      if (initargs[i] != null && !(clazz.isInstance(initargs[i]))) {
        throw new IllegalArgumentException("Object : " + initargs[i]
            + " is not an instance of " + clazz);
      }
    }

    try {
      Constructor<T> meth = theClass.getDeclaredConstructor(parameterTypes);
      meth.setAccessible(true);
      return meth.newInstance(initargs);
    } catch (Exception e) {
      throw new RuntimeException("Unable to instantiate " + theClass.getName(), e);
    }
  }
Create an object of the given class.
@param theClass
@param parameterTypes
         an array of parameterTypes for the constructor
@param initargs
         the list of arguments for the constructor
standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/utils/JavaUtils.java