标签:out his err 方法 str sys end 就是 print
泛型简而言之就是类型的参数化
泛型分为泛型接口、泛型类和泛型方法,不存在泛型数组。
举例
//泛型类;
public class Data<T> {
private T data;
public Data(T data) {
this.data = data;
}
public T getData() {
return data;
}
}
public class Test02 {
public static void main(String[] args) {
Data<String> data = new Data<String>("data");
Data<Integer> data1 = new Data<Integer>(2);
Data<Number> data2 = new Data<Number>(3);
getData(data);
getData(data1);
getNumbeUpperrData(data1);
getNumberLowerData(data2);
}
//通配符;
public static void getData(Data<?>data) {
System.out.println(data.getData());
}
//上限使用extends;
public static void getNumbeUpperrData(Data<? extends Number>data) {
System.out.println(data.getData());
}
//下限使用super
public static void getNumberLowerData(Data<? super Integer> data) {
System.out.println(data.getData());
}
}
参考
https://www.cnblogs.com/lwbqqyumidi/p/3837629.html
标签:out his err 方法 str sys end 就是 print
原文地址:https://www.cnblogs.com/LynnMin/p/9461583.html