2016-11-11 61 views
1

的我有一個像下面名稱衝突,因爲同一消失

public interface IDrawerItem<T, VH extends RecyclerView.ViewHolder> extends IItem<T, VH>, IExpandable<T, IDrawerItem>, ISubItem<IDrawerItem, IDrawerItem> { 
    void bindView(VH holder, List payloads); 

} 

林的接口收到以下錯誤

Error:(44, 10) error: name clash: bindView(VH#1,List) in IDrawerItem and bindView(VH#2,List) in IItem have the same erasure, yet neither overrides the other where VH#1,VH#2 are type-variables: VH#1 extends ViewHolder declared in interface IDrawerItem VH#2 extends ViewHolder declared in interface IItem

爲什麼會這樣呢?

+0

在其中一個超接口中聲明瞭「bindView」方法嗎?你想覆蓋它或超載嗎? – khelwood

+0

我試圖覆蓋它 –

+1

你只能覆蓋實現。 – khelwood

回答

3

簡答:因爲簽名不能改變。擴展接口只是向接口添加更多特徵。

覆蓋只能在類中完成,而不能在接口中完成。您無法更新簽名,但可以使用相同簽名對該方法進行不同的實現。

接口只顯示一個簽名,它必須在實現它的類中可用。由於這個原因,你可以改變(覆蓋)子類中的實現。方法簽名(名稱和參數)保持不變,所以它仍然符合接口。沒有實現可以在接口中重寫,因此它只顯示任何實現此接口的類中都有這樣的方法,並且它可以從實例化對象中調用。