2015-05-29 43 views
2

所以我有一個接口的Foo構造,如:實現一個可擴展可比的接口

public interface Foo<T extends Comparable<? super T>>

,我想在我的課吧好像來實現富:

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

回答

3

你的語法是有點過。嘗試將界限移動到T的聲明中,如下所示:

public class Bar<T extends Comparable<? super T>> implements Foo<T> { 
    ... 
} 
+0

噢,天哪,是它?!哇,我真的只是花時間試圖解決這個問題。 – Flameancer

+0

...因爲在這種情況下'Bar'是_declaring_'',並且只是將它作爲_parameter_傳遞給'Foo'。就像當你聲明一個變量並把它傳遞給一個方法時,聲明的類型必須滿足接收者的邊界才能進行編譯。 –