![](/img/trans.png)
[英]How to implement an interface with an enum, where the interface extends Comparable?
[英]Implement an interface that extends comparable
所以我有一個接口Foo構造如下:
public interface Foo<T extends Comparable<? super T>>
我正在嘗試在我的班級欄中實現Foo,例如:
public class Bar<T> implements Foo<T>
但我得到錯誤type argument T#1 is not within bounds of type-variable T#2
但是當我嘗試將Foo實現為:
public class Bar<T> implements Foo<T extends Comparable<? super T>>
我得到> expected
和<identifier> expected
您的語法有些偏離。 嘗試將邊界移動到T
的聲明中,如下所示:
public class Bar<T extends Comparable<? super T>> implements Foo<T> {
...
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.