package enums;
import flect.Constructor;
import flect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
public class Refance2 {
@Test
public void test1() throws Exception{
尽管如此英语 Class clazz= Class.forName("enums.Person");
Constructor c=Constructor(null);
Person p=(Person) c.newInstance(null我的国庆假期作文);
System.out.println(p.name);
}
@Test
public void test2() throws Exception{
Class clazz=Class.forName("enums.Person");
Constructor c=Constructor(String.class);
Person p=(Person) c.newInstance("王亚楠");
System.out.println(p.name);
}
@Test
public void test3() throws Exception{
Class clazz=Class.forName("enums.Person");
Constructor v=Constructor(String.class,int.class);
Person p=(Person) v.newInstance("王亚楠",123);
System.out.println(p.密云冶仙塔name);
}
@Test
public 早安心语最新void test4() throws Exception{
Class clazz=Class.forName("enums.Person");
Constructor c=DeclaredConstructor(List.class);
c.tAccessible(true);//暴力反射
Person p=(Person) c.newInstance(new ArrayList());
System.out.println(p.name+"4");
}
@Test//创建对象的另外一种途径
public void冰雪女神 test5() throws科学手抄报 Exception{
Class白癜风不能吃什么 clazz=Class.forName("enums.Person");
Person p=(Person) wInstance();bzha
System.out.println(p.name);
}
}
class Person{
public String name="王亚楠";
public Person() {
System.out.println("person");
}
public Person(String name)
{
System.out.println("name"+name);
}
public Person(String name,int password){
System.out.println(name+":::"+password);
}
private Person(List list){
System.out.println("list");
}
}