我正在尝试通过接口在Java中实现简单队列,但出现错误:
<td title='Full Text about School 1'>School 1 Data</td>
<td title='Full Text about School 2'>School 2 Data</td>
...
<td title='Full Text about School X'>School X Data</td>
这是我的代码:
接口:
Error:(9, 17) java: name clash: enqueue(T) in main.QueueImpl and enqueue(java.lang.Object) in main.Queue have the same erasure, yet neither overrides the other
实施:
public interface Queue<T> {
void enqueue(T o);
T dequeue();
int size();
}
实现入队方法有什么问题?
答案 0 :(得分:2)
更改您的实现,以将泛型传递给 接口 。喜欢,
public class QueueImpl<T> implements Queue<T> {
按原样,它知道Queue
是通用的,但它被视为原始类型。