我有一个像下面这样的界面
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
为什么会这样?
最佳答案
简短回答:因为无法更改签名。扩展接口(interface)只是向接口(interface)添加更多签名。
重写只能在类中进行,不能在接口(interface)中进行。您无法更新签名,但可以使用相同的签名对该方法进行不同的实现。
接口(interface)只显示一个签名,该签名必须在实现它的类中可用。因此,您可以更改(覆盖)子类中的实现。方法签名(名称和参数)保持不变,因此它仍然符合接口(interface)。接口(interface)中没有可重写的实现,因此它仅表明在实现此接口(interface)的任何类中都有这样的方法,并且可以从实例化对象调用它。
关于java - 由于相同的删除而导致名称冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40548146/