-1
我想用接口參數化泛型,Eclipse告訴我方法abc()
沒有實現類型T
。當然,由於T
是一個接口,因此它不會實現,程序會在運行時計算出真正的T
。所以,如果有人能幫我解決這個問題,我會非常感激。java接口和參數類型
我有這樣的:當你已經將它定義T
是Object
型
interface myInterface {
String abc();
}
class myClass<T> implements myClassInterface<T> {
String myMethod() {
T myType;
return myType.abc(); // here it says that abc() is not implemented for the type T
}
}
public class Main{
public static void Main(String[] arg) {
myClassInterface<myInterface> something = new myClass<myInterface>;
}
}
哪裏定義myClassInterface? –
T是一個通用類型。與界面的連接在哪裏? –
[有界泛型類型](https://docs.oracle.com/javase/tutorial/java/generics/bounded.html)是你需要的 –