加载器是个好东西
public static void main(String[] args) throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException { // 反射String类的所有构造方法 Class clz = Student.class; System.out.println("所有构造方法"); // Constructor[] cons = clz.getConstructors(); Constructor[] cons = clz.getDeclaredConstructors(); for (Constructor con : cons) { // System.out.println("访问修饰权限:" + // Modifier.toString(con.getModifiers())); // System.out.println("方法名:" + con.getName()); // System.out.println("****************************"); System.out.println(Modifier.toString(con.getModifiers()) + " " + con.getName()); } //找无参的构造方法 Student s = new Student(); Constructor con = clz.getDeclaredConstructor(); Object obj = con.newInstance(); System.out.println(obj); //找带string,int类型参数的构造方法 Student s = new Student("zhangsan",12) con = clz.getDeclaredConstructor(String.class, int.class); obj = con.newInstance("zhangsan", 12); System.out.println(obj); con = clz.getDeclaredConstructor(String.class); }