Vector v = new Vector();
//向v中加入了一些元素
。
Enumeratrion e = v.elements();//此时只返回一个接口,接口的功能谁来实现的?
e.hasMoreElements();
e.nextElement();
就问调用上面两个函数时,实谁来实现的呢?
//向v中加入了一些元素
。
Enumeratrion e = v.elements();//此时只返回一个接口,接口的功能谁来实现的?
e.hasMoreElements();
e.nextElement();
就问调用上面两个函数时,实谁来实现的呢?
return new Enumeration<E>() {
int count = 0; public boolean hasMoreElements() {
return count < elementCount;
} public E nextElement() {
synchronized (Vector.this) {
if (count < elementCount) {
return (E)elementData[count++];
}
}
throw new NoSuchElementException("Vector Enumeration");
}
};
}
Collection c = new ArrayList();
c.(Arraylist中实Collection中的抽象方法)那这里说的Enumerator又是怎么样的呢?