Java Class New Instance newInstance(Class clazz, Class[] parameterTypes, Object[] initargs)

Here you can find the source of newInstance(Class clazz, Class[] parameterTypes, Object[] initargs)

Description

new Instance

License

Open Source License

Declaration

static <T> T newInstance(Class<T> clazz,
            Class<?>[] parameterTypes, Object[] initargs)
            throws InvocationTargetException 

Method Source Code

//package com.java2s;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class Main {
    static <T> T newInstance(Class<T> clazz, Class<?>[] parameterTypes,
            Object[] initargs) throws InvocationTargetException {
        try {/*from w w w.j a  va  2  s  . co m*/
            Constructor<T> c = clazz.getDeclaredConstructor(parameterTypes);
            c.setAccessible(true);
            return c.newInstance(initargs);
        } catch (SecurityException e) {
            throw new RuntimeException(e);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        } catch (IllegalArgumentException e) {
            throw new RuntimeException(e);
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. newInstance(Class clazz)
  2. newInstance(Class clazz)
  3. newInstance(Class clazz)
  4. newInstance(Class clazz)
  5. newInstance(Class clazz, Class[] argumentTypes, Object[] arguments)
  6. newInstance(Class cls)
  7. newInstance(Class cls)
  8. newInstance(Class cls, Object... args)
  9. newInstance(Class clz, Class argType, K arg)