泛型
- JAVA 的参数化类型 称为 泛型
泛型类的设计
Learn12.java
public class Learn12<T>{
private T flag;
public Learn12(T flag){
this.flag = flag;
}
public T getDisc(){
return flag;
}
public static void main(String[] args){
Learn12<String> strClass = new Learn12<String>("=String=");
System.out.println( strClass.getDisc() );
Learn12<Integer> intClass = new Learn12<Integer>(100);
System.out.println(intClass.getDisc());
}
}
运行
=String=
100