簡體   English   中英

實現可擴展的接口

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM