Java Class New Instance newInstance(String className)

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

Description

new Instance

License

Open Source License

Declaration

@SuppressWarnings("unchecked") 
    public static <T> T newInstance(String className)
            throws ClassNotFoundException, InstantiationException, IllegalAccessException 

Method Source Code

//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License");

public class Main {
    @SuppressWarnings("unchecked") // we don't know what T is until runtime
    public static <T> T newInstance(String className)
            throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        return newInstance(ClassLoader.getSystemClassLoader(), className);
    }/*from   w ww  . java  2 s  .  c om*/

    @SuppressWarnings("unchecked") // we don't know what T is until runtime
    public static <T> T newInstance(ClassLoader classLoader, String className)
            throws ClassNotFoundException, IllegalAccessException, InstantiationException {
        if (className == null) {
            throw new ClassNotFoundException("Can not instantiate class. className must not be null");
        }
        return (T) classLoader.loadClass(className).newInstance();
    }
}

Related

  1. newInstance(String className)
  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)