代码中有一个错误,说无法创建 E 的通用数组。谁能帮助我谢谢
**Q = new E[N];**
这是完整的代码;
package org.circular;
public class CircularArrayQueue<E> implements QueueADT<E> {
private static final int capacity = 5;
private E[] Q;
private final int N; // capacity
private int f = 0;
private int r = 0;
public CircularArrayQueue() {
this(capacity);
}
public CircularArrayQueue(int capacity) {
N = capacity;
Q = new E[N];
}
public int size() {
if (r > f)
return r - f;
return N - f + r;
}
public boolean isEmpty() {
return (r == f) ? true : false;
}
public boolean isFull() {
int diff = r - f;
if (diff == -1 || diff == (N - 1))
return true;
return false;
}
public void enqueue(E element) throws FullQueueException {
if (isFull()) {
throw new FullQueueException("Full");
} else {
Q[r] = element;
r = (r + 1) % N;
}
}
public E dequeue() throws EmptyQueueException {
E item;
if (isEmpty()) {
throw new EmptyQueueException("Empty");
} else {
item = Q[f];
Q[f] = null;
f = (f + 1) % N;
}
return item;
}
@Override
public E front() throws EmptyQueueException {
if (isEmpty()) {
throw new EmptyQueueException("Empty");
}
return null;
}
}