Java Class New Instance newInstance(Class cls)

Here you can find the source of newInstance(Class cls)

Description

new Instance

License

Open Source License

Declaration

public static <T> T newInstance(Class<T> cls) throws IllegalArgumentException, IllegalAccessException,
            InvocationTargetException, SecurityException, NoSuchMethodException, InstantiationException 

Method Source Code

//package com.java2s;
/*/*w  ww.j a v  a2  s.com*/
 * Beanfabrics Framework Copyright (C) by Michael Karneim, beanfabrics.org
 * Use is subject to license terms. See license.txt.
 */

import java.lang.reflect.Constructor;

import java.lang.reflect.InvocationTargetException;

public class Main {
    public static <T> T newInstance(Class<T> cls) throws IllegalArgumentException, IllegalAccessException,
            InvocationTargetException, SecurityException, NoSuchMethodException, InstantiationException {
        Constructor<T> constr = cls.getConstructor((Class[]) null);
        if (!constr.isAccessible()) {
            constr.setAccessible(true);
        }
        T result = constr.newInstance((Object[]) null);
        return result;
    }
}

Related

  1. newInstance(Class clazz)
  2. newInstance(Class clazz)
  3. newInstance(Class clazz, Class[] argumentTypes, Object[] arguments)
  4. newInstance(Class clazz, Class[] parameterTypes, Object[] initargs)
  5. newInstance(Class cls)
  6. newInstance(Class cls, Object... args)
  7. newInstance(Class clz, Class argType, K arg)
  8. newInstance(Class componentType, int size)
  9. newInstance(Class elementType, int len)