久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術(shù)文章
文章詳情頁

java - 一個泛型標(biāo)簽問題

瀏覽:140日期:2023-11-24 10:46:53

問題描述

新手問一個泛型問題

public static void main(String[] args) {ArrayList<Student> al = new ArrayList<>();al.add(new Student('大石榴',17,100));al.add(new Student('地雷',20,80));al.add(new Student('張大炮',21,60));Comparator<Student> cp = new Comparator<Student>() {@Override public int compare(Student o1, Student o2) {return o1.getAge() - o2.getAge(); }}; Collections.max(al, cp);//public static <T> T max(Collection<? extends T> coll, Comparator<? super T> comp)//這是max方法的源碼.// <T> 這個泛型在哪獲取到的?for(Student st : al){ System.out.println(st);} }

問題解答

回答1:

Java中的泛型都是使用了類型擦除,你這里的<T> 只是一個類型變量。這個方法里面也只是用來代表@param <T> the class of the objects in the collection

標(biāo)簽: java
相關(guān)文章:
主站蜘蛛池模板: 南京市| 兰州市| 喜德县| 长岛县| 三原县| 龙井市| 南汇区| 绍兴市| 宁城县| 高雄县| 玛沁县| 宜昌市| 山西省| 七台河市| 大理市| 枣庄市| 布拖县| 岳西县| 会泽县| 高碑店市| 南宁市| 旬邑县| 芷江| 三门县| 宁海县| 漯河市| 桃江县| 南丹县| 广州市| 凭祥市| 平舆县| 隆安县| 永泰县| 辽阳市| 吕梁市| 大埔区| 天门市| 徐汇区| 蒙自县| 阜平县| 潞西市|