0
我有三個接口:如何實現已經參數化並擴展了兩個其他接口的接口?
public interface IAggregable<TElement extends IAggregable<TElement, TResult>, TResult> {
TResult aggregate(TResult intermediateResult);
}
public interface IDeeplyCloneable<TElement extends IDeeplyCloneable<TElement>> {
TElement deepClone();
}
public interface IContainer<TElement extends IAggregable<TElement, TResult> & IDeeplyCloneable<TElement>, TResult> {
TResult aggregateAllElements();
TElement cloneElementAtIndex(int index);
}
我嘗試落實最後一個;
public class GTZCH<TElement, TResult> implements IContainer<TElement, TResult> {
public GTZCH() {
// TODO Auto-generated constructor stub
}
@Override
public TResult aggregateAllElements() {
// TODO Auto-generated method stub
return null;
}
@Override
public TElement cloneElementAtIndex(int index) {
// TODO Auto-generated method stub
return null;
}
}
,但我得到一個編譯錯誤:
Bound mismatch: The type TElement is not a valid substitute for the bounded parameter <TElement extends
IAggregable<TElement,TResult> & IDeeplyCloneable<TElement>> of the type IContainer<TElement,TResult>
什麼&
運營商在exends部分是指,我認爲應該有一個昏迷不&擴展多個接口。
如何實現該接口的方式我不會使用原始類型?
這是'型和一個'約束。請參閱[關於類型邊界的教程](https://docs.oracle.com/javase/tutorial/java/generics/bounded.html)。 –