泛型繼承Comparable接口

今天遇到一個不認識的語法,記錄一下:

貼一個stackoverflow的答案:

public class R<T extends Comparable>

This means that the type parameter must support comparison with other instances of its own type, via the Comparable interface.

( 這句話的大概意思就是你的泛型參數必須實現Comparable接口來達到自己的泛型實例之間能相互比較的目的。

An example of such a class is provided in the Oracle tutorial Object Ordering. Note the similar pattern to T extends Comparable in the excerpt below:

public class Name implements Comparable {

public int compareTo(Name n) { … }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章