最近在学java,但是不太能理解java里的generic是如何实现的~求大神们指导一下~
解决方案 »
- JFileChooser如何添加多个文件类型过滤?
- 关于DatabaseMetaData
- 求高手指点迷津,我想学Java从哪里开始着手!
- Eclipse的Visual Editor设计了一个JFrame时,有时候图形显示不出来了
- 程序错误
- 谁有JAVA EXCEL API
- 要从一个表中取出数据 该表中有 2万条数据 通过jdbc 连接 如何实现
- java中一个参数想传到一个jsp里,即使这个java页关闭,参数也不消失,该怎么传~
- the super developer for Swing/AWT/JFC , come in please
- 新手送分。入门问题
- 请教下jar文件到底是怎么打开的?
- 如何快速学好JAVA
package com.tur.demo;import java.util.AbstractQueue;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
import java.util.NoSuchElementException;public class CircularArrayQueue<E> extends AbstractQueue<E> {
private E[] elements;
private int head;
private int tail;
private int count;
private int modCount; public CircularArrayQueue(int capacity) {
elements = (E[]) new Object[capacity]; // 不能 new E[capacity]
head = 0;
tail = 0;
count = 0;
modCount = 0;
} public boolean offer(E newElement) {
assert newElement != null; if (count < elements.length) {
elements[tail] = newElement;
tail = (tail + 1) % elements.length;
count++;
modCount++; return true;
} else {
return false;
}
} public E poll() {
if (count == 0) return null;
E r = elements[head];
head = (head + 1) % elements.length;
count--;
modCount++; return r;
} public E peek() {
if (count == 0) return null;
return elements[head];
} public int size() {
return count;
} public Iterator<E> iterator() {
return new QueueIterator();
} // 迭代器的实现
private class QueueIterator implements Iterator<E> {
private int modCountAtConstruction;
private int offset; public QueueIterator() {
modCountAtConstruction = modCount;
offset = 0;
} public E next() {
if (!hasNext()) {
throw new NoSuchElementException();
} E e = elements[(head + offset) % elements.length];
offset++; return e;
} public boolean hasNext() {
if (modCountAtConstruction != modCount) {
throw new ConcurrentModificationException();
}
return offset < count;
} public void remove() {
throw new UnsupportedOperationException();
}
}
}