泛型 Generic Types
import java.util.ArrayList;
import java.util.List;
public class Test01 {
public static void main(String[] args) {
List<Integer> nums = new ArrayList<Integer>();
nums.add(25);
Student stu1 = new Student("tom");
stu1.obj = 25;
stu1.show();
Student2<String> stu2=new Student2<String>("jack");
stu2.show();
print("tom");
print(20);
print(13.5);
}
public static <T> void print(T t){
System.out.println(t.getClass());
}
}
class Student {
Object obj;
public Student(Object obj) {
this.obj = obj;
}
public void show() {
System.out.println(obj);
}
}
class Student2<T> {
T t;
public Student2(T t) {
this.t = t;
}
public void show(){
System.out.println(t);
}
}