Java Class New Instance newInstanceOf(String className)

Here you can find the source of newInstanceOf(String className)

Description

new Instance Of

License

Open Source License

Declaration

public static Object newInstanceOf(String className)
            throws InstantiationException, IllegalAccessException, IllegalArgumentException,
            InvocationTargetException, ClassNotFoundException, NoSuchMethodException, SecurityException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    public static Object newInstanceOf(String className)
            throws InstantiationException, IllegalAccessException, IllegalArgumentException,
            InvocationTargetException, ClassNotFoundException, NoSuchMethodException, SecurityException {
        Class<?> c = Class.forName(className);
        Constructor<?> constructor = c.getConstructor();
        return constructor.newInstance();
    }/*from w  w  w  .j a v  a 2 s . co  m*/
}

Related

  1. newInstanceFromClass(final Class clazz)
  2. newInstanceFromClassName(String className, Class classType)
  3. newInstanceFromUnknownArgumentTypes(Class cls, Object[] args)
  4. newInstanceHard(String name)
  5. newInstanceOf(Class clazz)
  6. newInstanceOrThrow(final Class clazz)
  7. newInstancesViaMetaAnnotation(Class declarator, Class metaAnnotationClass, Class expected)
  8. newInstanceViaAnnotation(Class declarator, Annotation annotation, Class expected, Annotation parameter)
  9. newInstanceWithDefaults(Class annotationType)