Here you can find the source of newInstance(String className, Class
public static <T> T newInstance(String className, Class<T> castTo)
//package com.java2s; //License from project: Open Source License public class Main { public static <T> T newInstance(String className, Class<T> castTo) { return castTo.cast(newInstance(forName(className))); }//from w w w . j a va 2 s . c om public static <T> T newInstance(Class<T> clazz) { try { return clazz.newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new IllegalStateException(e); } } public static Class<?> forName(String className) { try { return Class.forName(className); } catch (ClassNotFoundException | NoClassDefFoundError e) { throw new IllegalStateException(e); } } }