文章詳情頁
java - 一個泛型標簽問題
瀏覽:118日期: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
相關文章:
1. javascript - node.js服務端渲染解疑2. javascript - 求助關于js正則問題3. html5 - 如何解決bootstrap打開模態(tài)modal窗口引起頁面抖動?4. javascript - 求助這種功能有什么好點的插件?5. objective-c - ios百度地圖定位問題6. 微信開放平臺 - Android調用微信分享不顯示7. html - css 如何添加這種邊框?8. html5 - rudy編譯sass的時候有中文報錯9. javascript - 關于定時器 與 防止連續(xù)點擊 問題10. 為何 localStorage、sessionStorage 屬于html5的范疇,但是為何 IE8卻支持?
排行榜
