界面和一个类。名称冲突:相同的擦除,但都不会覆盖其他 [英] interface and a class. name clash: same erasure, yet neither overrides other
问题描述
我有一个接口,当我尝试实现其中一个方法时,我收到此错误:
GenericQueue中的名称冲突:入队(T#1)和IGenericQueue中的入队(T#2)相同的擦除,但是在T#1,T#2都是类型变量的情况下都不会覆盖另一个:
T#1 extends在类GenericQueue中声明的Comparable
T#2扩展在接口IGenericQueue$ b中声明的Comparable $ b这里是代码:
I have an interface, and when I try to implement one of its methods, I get this error : "name clash: enqueue(T#1) in GenericQueue and enqueue(T#2) in IGenericQueue have the same erasure, yet neither overrides the other where T#1 ,T#2 are type variables: T#1 extends Comparable declared in class GenericQueue T#2 extends Comparable declared in interface IGenericQueue " here's the code :
public interface IGenericQueue <T extends Comparable> {
public void enqueue(T j);
..
}
public class GenericQueue<T extends Comparable> implements IGenericQueue {
....
public void enqueue(T j) // the error is in this line.
{
if(rear == maxSize -1)
rear = -1; // means you have reached the last element start again ?
queArray[++rear] = j;
nItems ++ ;
}
}
推荐答案
您的 GenericQueue
正在实施原始接口 IGenericQueue
,因此其 T
与 IGenericQueue
中的 T
不同。在 implements
子句中添加< T>
:
Your GenericQueue
is implementing the raw interface IGenericQueue
, so its T
is different than the T
in IGenericQueue
. Add the <T>
in the implements
clause:
public class GenericQueue<T extends Comparable> implements IGenericQueue<T> {
// ^^^
所以你用相同的<实现通用接口code> T 。
这篇关于界面和一个类。名称冲突:相同的擦除,但都不会覆盖其他的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!