Here you can find the source of newInstance()
public static Object newInstance()
//package com.java2s; //License from project: Apache License public class Main { public static Object newInstance() { try {/* ww w. j a va 2 s . c o m*/ return getTraceClass(1).newInstance(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } return null; } public static Class getTraceClass(int i) { StackTraceElement[] stackTrace = new RuntimeException().getStackTrace(); StackTraceElement ele = stackTrace[1 + i]; try { String className = ele.getClassName(); return Class.forName(className); } catch (ClassNotFoundException e) { e.printStackTrace(); return null; } } }