[問題]泛型當引數的問題

看板java作者 (骨頭)時間19年前 (2007/01/07 17:16), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/2 (看更多)
我的問題很簡單, 我有一個類別Person implements Comparable介面, 我有一個ArrayList<Person> , 我有一個quicksort指定引數如下 private void quicksort( ArrayList<Comparable> a,int left, int right) { 卻發生如下的錯誤訊息 quicksort(java.util.ArrayList<java.lang.Comparable>,int,int) in myClass cannot be applied to (java.util.ArrayList<tony1223.DS.Person>,int,int) quicksort(cl.personlist,0,cl.personlist.size()-1); 理論上我的Person有implements Comparable , 這應該不會是編譯時期的錯誤才對呀... ──────────────────────────────── 問題是將兩邊的泛型統一型態後就解決了, 將兩邊都改成<Comparable> 比較符合我的想法, 只是對於這樣的錯誤覺得很奇怪。@@ 畢竟我的Person應該也可以視為Comparable的物件 為甚麼會被擋呢...:( -- String temp="relax"; | Life just like programing while(buringlife) String.forgot(temp); | to be right or wrong while(sleeping) brain.setMemoryOut(); | need not to say stack.push(life.running); | the complier will stack.push(scouting.buck()); | answer your life stack.push(bowling.practice()); | Bone everything -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.134.27.68 ※ 編輯: TonyQ 來自: 220.134.27.68 (01/07 17:17)
文章代碼(AID): #15eBfy-d (java)
討論串 (同標題文章)
文章代碼(AID): #15eBfy-d (java)