开发者

java.util.vector$1

enumeration e=vector.elements

But vector class does not implement Enumeration, then how comes it is returning Enumeration Reference. But e is refering to java.util.vector$1 . 开发者_JS百科What is "Vector$1"???


Vector$1 is an anonymous class. Vector.elements() creates a new instance of this anonymous class, which implements the Enumeration interface.

Here's the source code for Vector.elements() (badly formatted, as usual):

public Enumeration<E> elements() {
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");
    }
};
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜