Constructor类相关方法:
package com.javareflection;
import java.lang.reflect.Constructor;
public class Person {
public static void main(String[] args) throws Exception{
// 1. 先获取User类的Class对象
Class<?> aClass = Class.forName("com.javareflection.User");
// 2. 通过无参构造器创建对象实例
Object o = aClass.newInstance();
System.out.println(o);
// 3. 通过public的有参构造器创建对象实例
Constructor<?> constructor = aClass.getConstructor(String.class);
Object ton = constructor.newInstance("Ton");
System.out.println(ton);
Constructor<?> constructor1 = aClass.getDeclaredConstructor(int.class, String.class);
constructor1.setAccessible(true<