Java Class New Instance newInstance(String className)

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

Description

Return a new instance of the class using the default constructor.

License

Apache License

Declaration

public static Object newInstance(String className) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*from   w  ww. j ava 2  s  .  c om*/
     * Return a new instance of the class using the default constructor.
     */
    public static Object newInstance(String className) {
        try {
            Class<?> cls = Class.forName(className);
            return cls.newInstance();
        } catch (Exception e) {
            String msg = "Error constructing " + className;
            throw new IllegalArgumentException(msg, e);
        }
    }
}

Related

  1. newInstance(String aclass)
  2. newInstance(String className)
  3. newInstance(String className)
  4. newInstance(String className)
  5. newInstance(String className)
  6. newInstance(String className)
  7. newInstance(String className)
  8. newInstance(String className)
  9. newInstance(String className)