Create an object for the given class.

@param theClass
class of which an object is created

@param parameterTypes
an array of parameterTypes for the constructor
@param initargs
the list of arguments for the constructor
@return a new object
769514
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(
          "Constructor parameter types don't match constructor arguments");
    }
    for (int i = 0; i < parameterTypes.length; i++) {
      Class<?> clazz = parameterTypes[i];
      if (!(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(e);
    }
  }
706822
public static void initClass() {

        // registers a factory for creating new instances of this widget
        CmsWidgetFactoryRegistry.instance().registerFactory(WIDGET_TYPE, new I_CmsFormWidgetFactory() {

            /**
             * @see org.opencms.gwt.client.ui.input.form.I_CmsFormWidgetFactory#createWidget(java.util.Map, com.google.common.base.Optional)
             */
            public I_CmsFormWidget createWidget(Map<String, String> widgetParams, Optional<String> defaultValue) {

                return new CmsSelectBox(widgetParams, true);
            }
        });

        CmsWidgetFactoryRegistry.instance().registerFactory(WIDGET_TYPE_NOTNULL, new I_CmsFormWidgetFactory() {

            /**
             * @see org.opencms.gwt.client.ui.input.form.I_CmsFormWidgetFactory#createWidget(java.util.Map, com.google.common.base.Optional)
             */
            public I_CmsFormWidget createWidget(Map<String, String> widgetParams, Optional<String> defaultValue) {

                return new CmsSelectBox(widgetParams, false);
            }
        });

    }
445318
protected final void init() {

    Type genericComponentType = null;
    Type genericKeyType = null;
    if (this.type instanceof GenericArrayType) {
      GenericArrayType arrayType = (GenericArrayType) this.type;
      genericComponentType = arrayType.getGenericComponentType();
    }
    if (genericComponentType == null) {
      TypeVariable<?> keyTypeVariable = null;
      TypeVariable<?> componentTypeVariable = null;
      if (this.retrievalClass.isArray()) {
        genericComponentType = this.retrievalClass.getComponentType();
      } else if (Collection.class.isAssignableFrom(this.retrievalClass)) {
        componentTypeVariable = CommonTypeVariables.TYPE_VARIABLE_COLLECTION_ELEMENT;
      } else if (Map.class.isAssignableFrom(this.retrievalClass)) {
        componentTypeVariable = CommonTypeVariables.TYPE_VARIABLE_MAP_VALUE;
        keyTypeVariable = CommonTypeVariables.TYPE_VARIABLE_MAP_KEY;
      }
      if (componentTypeVariable != null) {
        genericComponentType = resolveTypeVariable(componentTypeVariable, this);
        if (genericComponentType == null) {
          genericComponentType = componentTypeVariable;
        }
      }
      if (keyTypeVariable != null) {
        genericKeyType = resolveTypeVariable(keyTypeVariable, this);
        if (genericKeyType == null) {
          genericKeyType = keyTypeVariable;
        }
      }
    }
    if (genericComponentType == null) {
      this.componentType = null;
    } else {
      this.componentType = create(genericComponentType, this.definingType);
    }
    if (genericKeyType == null) {
      this.keyType = null;
    } else {
      this.keyType = create(genericKeyType, this.definingType);
    }
  }
1058849
private FunctionType createNativeFunctionTypeWithVarArgs(
      JSType returnType, JSType... parameterTypes) {
    return createNativeFunctionType(
        returnType, createParametersWithVarArgs(parameterTypes));
  }
58476
private static Object[] getInitParameters(Class<?>[] parameterTypes) {
        int length = parameterTypes.length;
        Object[] result = new Object[length];
        for (int i = 0; i < length; i++) {
            if (parameterTypes[i].isPrimitive()) {
                Object init = ClassUtil.getPrimitiveDefaultValue(parameterTypes[i]);
                result[i] = init;
                continue;
            }
            result[i] = null;
        }
        return result;
    }
977852
@Override
    public void init(final Class<? extends State> stateClass) throws InitializationException {
        try {
            currentState = getState(stateClass);
            change.firePropertyChange(STATE_CHANGE, null, currentState.getClass());
        } catch (NotAvailableException ex) {
            throw new InitializationException(this, ex);
        }
    }
1078121
public static Object getGenInstance(Class<?> cls, Object... args) throws ParserException
    {
        Class<?> parserClass = getGenClass(cls);
        try
        {
            if (args.length == 0)
            {
                return parserClass.newInstance();
            }
            else
            {
                for (Constructor constructor : parserClass.getConstructors())
                {
                    Class[] parameterTypes = constructor.getParameterTypes();
                    if (parameterTypes.length == args.length)
                    {
                        boolean match = true;
                        int index = 0;
                        for (Class c : parameterTypes)
                        {
                            if (!c.isAssignableFrom(args[index++].getClass()))
                            {
                                match = false;
                                break;
                            }
                        }
                        if (match)
                        {
                            return constructor.newInstance(args);
                        }
                    }
                }
                throw new IllegalArgumentException("no required constructor for "+cls);
            }
        }

        catch (InstantiationException | IllegalAccessException | SecurityException | IllegalArgumentException | InvocationTargetException ex)
        {
            throw new ParserException(ex);
        }
    }
135184
public Control createRequestControl(Class<?>[] paramTypes, Object[] params) {
		Constructor<?> constructor = ClassUtils.getConstructorIfAvailable(requestControlClass, paramTypes);
		if (constructor == null) {
			throw new IllegalArgumentException("Failed to find an appropriate RequestControl constructor");
		}

		Control result = null;
		try {
			result = (Control) constructor.newInstance(params);
		}
		catch (Exception e) {
			ReflectionUtils.handleReflectionException(e);
		}

		return result;
	}
1271844
public static <T> T createInstance(Class<T> pClass, Object... pParams)
            throws InvocationTargetException {
        T value;

        try {
            // Create param and argument arrays
            Class[] paramTypes = null;
            if (pParams != null && pParams.length > 0) {
                paramTypes = new Class[pParams.length];
                for (int i = 0; i < pParams.length; i++) {
                    paramTypes[i] = pParams[i].getClass();
                }
            }

            // Get constructor
            Constructor<T> constructor = pClass.getConstructor(paramTypes);

            // Invoke and create instance
            value = constructor.newInstance(pParams);
        }
        /* All this to let InvocationTargetException pass on */
        catch (NoSuchMethodException nsme) {
            return null;
        }
        catch (IllegalAccessException iae) {
            return null;
        }
        catch (IllegalArgumentException iarge) {
            return null;
        }
        catch (InstantiationException ie) {
            return null;
        }
        catch (ExceptionInInitializerError err) {
            return null;
        }

        return value;
    }
104805
protected Object createObject (Class type) throws InvocationTargetException {
		// Use deferred construction if a non-zero-arg constructor is available.
		DeferredConstruction deferredConstruction = Beans.getDeferredConstruction(type, config);
		if (deferredConstruction != null) return deferredConstruction;
		return Beans.createObject(type, config.privateConstructors);
	}
640187
private void init_jdbcTypes() throws SQLException
    {
        ReportQuery q = (ReportQuery) getQueryObject().getQuery();
        m_jdbcTypes = new int[m_attributeCount];
        
        // try to get jdbcTypes from Query
        if (q.getJdbcTypes() != null)
        {
            m_jdbcTypes = q.getJdbcTypes();
        }
        else
        {
            ResultSetMetaData rsMetaData = getRsAndStmt().m_rs.getMetaData();
            for (int i = 0; i < m_attributeCount; i++)
            {
                m_jdbcTypes[i] = rsMetaData.getColumnType(i + 1);
            }
            
        }
    }
245859
public Node createOptionalParameters(JSType... parameterTypes) {
    FunctionParamBuilder builder = new FunctionParamBuilder(this);
    builder.addOptionalParams(parameterTypes);
    return builder.build();
  }
6178
public static void initClass() {

        // registers a factory for creating new instances of this widget
        CmsWidgetFactoryRegistry.instance().registerFactory(WIDGET_TYPE, new I_CmsFormWidgetFactory() {

            /**
             * @see org.opencms.gwt.client.ui.input.form.I_CmsFormWidgetFactory#createWidget(java.util.Map, com.google.common.base.Optional)
             */
            public I_CmsFormWidget createWidget(Map<String, String> widgetParams, Optional<String> defaultValue) {

                Map<String, CmsPair<String, Boolean>> entries = new HashMap<String, CmsPair<String, Boolean>>();
                String label = "Select";
                if (widgetParams.containsKey("label")) {
                    label = widgetParams.get("label");
                    widgetParams.remove("label");
                }
                for (Map.Entry<String, String> entry : widgetParams.entrySet()) {
                    entries.put(entry.getKey(), CmsPair.create(entry.getValue(), Boolean.FALSE));
                }
                CmsMultiSelectCell cell = new CmsMultiSelectCell(entries);
                cell.setOpenerText(label);
                CmsMultiSelectBox box = new CmsMultiSelectBox();
                box.addOption(cell);
                return box;
            }
        });
    }
1152553
public function create($documentClass, array $initializeArgs = array())
    {
        $document = new $documentClass($this);
        if (method_exists($document, 'initialize')) {
            call_user_func_array(array($document, 'initialize'), $initializeArgs);
        }

        return $document;
    }
79703
@SafeVarargs
    public static <T> Constructor<T> getDeclaredConstructor(final Class<T> cls, final Class<?>... parameterTypes) {
        Map<Class<?>[], Constructor<?>> constructorPool = classDeclaredConstructorPool.get(cls);
        Constructor<T> constructor = null;

        if (constructorPool != null) {
            constructor = (Constructor<T>) constructorPool.get(parameterTypes);
        }

        if (constructor == null) {
            try {
                constructor = cls.getDeclaredConstructor(parameterTypes);

                // SHOULD NOT set it true here.
                // constructor.setAccessible(true);
            } catch (NoSuchMethodException e) {
                // ignore.
            }

            if (constructor != null) {
                if (constructorPool == null) {
                    constructorPool = new ArrayHashMap<>(ConcurrentHashMap.class);
                    classDeclaredConstructorPool.put(cls, constructorPool);
                }

                constructorPool.put(parameterTypes.clone(), constructor);
            }
        }

        return constructor;
    }
1033172
public static CreateOptions getOpt(Class<? extends CreateOptions> theClass, CreateOptions... opts) {
    if (opts == null)
      return null;
    CreateOptions result = null;
    for (int i = 0; i < opts.length; ++i) {
      if (opts[i].getClass() == theClass) {
        if (result != null)
          throw new IllegalArgumentException("Multiple args with type " + theClass);
        result = opts[i];
      }
    }
    return result;
  }
858622
protected void init(int initialMaxSize, Class<T> type, Factory<T> factory) {
		this.size = 0;
		this.type = type;
		this.factory = factory;

		data = (T[]) Array.newInstance(type, initialMaxSize);

		if( factory != null ) {
			for( int i = 0; i < initialMaxSize; i++ ) {
				try {
					data[i] = createInstance();
				} catch( RuntimeException e ) {
					throw new RuntimeException("declareInstances is true, but createInstance() can't create a new instance.  Maybe override createInstance()?");
				}
			}
		}
	}