Public class Person{
Public T age;
Public Person (T age) {this. Age=age; }
}
//subclasses Student provides type
Public class Student extends Person{
Public Student (Integer age) {super (age); }
}
Public class ReflectDemo {
Public static void main (String [] args) throws the Exception {
ListStu=fun (a Student in the class, "1, 2");
System. The out. Println (stu);
}
Public static & lt; T> ListFun (Class Clazz, String seriable) throws the Exception {
//try to create two student object through reflection
ListStus=new ArrayList<> (a);
String [] which=seriable. Split (", ");
For (String age: which) {
//the following if you can not write an Integer. The class, but through the clazz reflection, but I can't get is the Object type
T stu=clazz. GetDeclaredConstructor (Integer. The class). NewInstance (Integer. The valueOf (age));
Stus. Add (stu);
}
Return stus;
}
}