java - 一個泛型標簽問題
問題描述
新手問一個泛型問題
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
相關文章:
1. debian - docker依賴的aufs-tools源碼哪里可以找到啊?2. angular.js使用$resource服務把數據存入mongodb的問題。3. docker - 如何修改運行中容器的配置4. macos - mac下docker如何設置代理5. docker start -a dockername 老是卡住,什么情況?6. docker網絡端口映射,沒有方便點的操作方法么?7. docker 下面創建的IMAGE 他們的 ID 一樣?這個是怎么回事????8. docker api 開發的端口怎么獲???9. dockerfile - 我用docker build的時候出現下邊問題 麻煩幫我看一下10. docker gitlab 如何git clone?

網公網安備