public class 泛型<T> {
private T ob; // 定义泛型成员变量
public 泛型(T ob) { //构造方法
this.ob = ob;
}
public T getOb() { //获取泛型类型
return ob;
}
public void showTyep() {
System.out.println("T的实际类型是: " + ob.getClass().getName());
}
public static void main(String[] args) {
泛型<Integer> intOb = new 泛型<Integer>(100); //Integer泛型
intOb.showTyep();
System.out.println("value= " + intOb.getOb());
System.out.println("----------------------------------");
泛型<String> strOb = new 泛型<String>("优快云_SEU_Calvin"); //String泛型
strOb.showTyep();
System.out.println("value= " + strOb.getOb());
}
}
使用泛型
最新推荐文章于 2024-10-03 16:46:54 发布