提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
类的新实例,泛型类型
/**from 时 代 Java 公 众 号 - nowjava.com**/ //package com.nowjava; public class Main { public static void main(String[] argv) throws Exception { Class clazz = String.class; System.out.println(newInstance(clazz)); } public static <T> T newInstance(Class<T> clazz) { try { return clazz.newInstance(); } catch (InstantiationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) {