Re: [問題] Collections.sort一個interface List

看板java作者 (叔叔你人真好)時間13年前 (2012/11/12 12:23), 編輯推噓4(402)
留言6則, 2人參與, 最新討論串2/2 (看更多)
※ 引述《shedoh (仙道)》之銘言: : 我自己是亂試過把 C 改成 => interface C<T> extends Comparable<T>{} 先看 sort() 的 definition: public static void sort(<T extends Comparable<? super T>>) 這是什麼意思? 也就是你丟進去的型 T,它本身必須 extends (impelments) Comparable<? super T> ? super T 又是什麼?就是那個 Comparable 的 generic type 必須是 T 的 super class T 是 C 的 super class 嗎? 不是。 就這樣了。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 147.8.127.102 ※ 編輯: superlubu 來自: 147.8.127.102 (11/12 12:23)

11/12 12:34, , 1F
抱歉不是很懂所以再請教一下,所以不能對interface sort囉?
11/12 12:34, 1F

11/12 12:36, , 2F
即便所有implement該interface的class都會實作comparable?
11/12 12:36, 2F

11/12 12:38, , 3F
還是有其他寫法可以達成類似我要的效果嗎?
11/12 12:38, 3F

11/12 15:12, , 4F
意思是C的Comparable的GenericType必須是C本身
11/12 15:12, 4F

11/12 15:13, , 5F
interface C<T> extends Comparable<C<T>>
11/12 15:13, 5F

11/12 17:27, , 6F
了解了...感謝
11/12 17:27, 6F
文章代碼(AID): #1Ge7cuto (java)
文章代碼(AID): #1Ge7cuto (java)