国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

java - 一個泛型標簽問題

瀏覽:112日期: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

標簽: java
相關文章:
主站蜘蛛池模板: 泸溪县| 宜章县| 长丰县| 嘉禾县| 西城区| 仙游县| 安丘市| 黄浦区| 固始县| 泸西县| 临颍县| 分宜县| 玉环县| 施甸县| 醴陵市| 洛隆县| 郓城县| 辛集市| 衡阳县| 太原市| 交口县| 时尚| 德安县| 庆城县| 合川市| 北海市| 晋城| 张家界市| 安西县| 滁州市| 五指山市| 庆城县| 花垣县| 眉山市| 泌阳县| 灵宝市| 博野县| 崇信县| 左贡县| 盖州市| 娱乐|