public static void doRegular() throws Exception { long start = System.currentTimeMillis(); for (int i = 0; i < 1000000; i + +) { A a = new A(); a.doSomething(); } System.out.println(System.currentTimeMillis() - start); } public static void doReflection() throws Exception { long start = System.currentTimeMillis(); for (int i = 0; i < 1000000; i + +) { A a = (A) Class.forName("com.franciszabala.playground.A") .newInstance(); a.doSomething(); } System.out.println(System.currentTimeMillis() - start); }
.newInstance()
Class.forName()