Day16_90_通过反射机制获取某个特定的构造方法
通过反射机制获取某个特定的构造方法
public class ReflectTest13 {
public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
//创建Class类
Class c= Class.forName("com.shige.Reflect.CustomerService");
//获取某个特定的构造方法
Constructor constructor=c.getDeclaredConstructor(String.class,String.class);
//利用获取到的构造方法创建对象
Object obj=constructor.newInstance("admin","123456");
//输出该对象
System.out.println(obj);
}
}