标签:code print ted one chm enum oid eth method
在概述中已经介绍了拥有 Class 对象大概可以干些什么事情,现在详细说明第一件事也是用得最多的一方面:创建对应运行时类的对象
public class TestNew {
public static void main(String[] args) throws InstantiationException, IllegalAccessException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException {
Class<Person> clazz = Person.class;
Person p1 = clazz.newInstance();
Constructor<Person> cons = clazz.getConstructor(int.class, String.class);
Person p2 = cons.newInstance(21, "cdf");
System.out.println(p1);// Person [age=0, name=null]
System.out.println(p2);// Person [age=21, name=cdf]
}
}
标签:code print ted one chm enum oid eth method
原文地址:http://www.cnblogs.com/chendifan/p/6569273.html