2016-11-11 60 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

简答:因为签名不能改变。扩展接口只是向接口添加更多特征。

覆盖只能在类中完成,而不能在接口中完成。您无法更新签名,但可以使用相同签名对该方法进行不同的实现。

接口只显示一个签名,它必须在实现它的类中可用。由于这个原因,你可以改变(覆盖)子类中的实现。方法签名(名称和参数)保持不变,所以它仍然符合接口。没有实现可以在接口中重写,因此它只显示任何实现此接口的类中都有这样的方法,并且它可以从实例化对象中调用。