Vector v = new Vector();
//向v中加入了一些元素

Enumeratrion e = v.elements();//此时只返回一个接口,接口的功能谁来实现的?
e.hasMoreElements();
e.nextElement();
就问调用上面两个函数时,实谁来实现的呢?

解决方案 »

  1.   

    看Vectior的源码,你来这儿问问题的功夫,自己看看源码都解决了。
      

  2.   

    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");
        }
    };
        }
      

  3.   

    你不想了解它的实现的话,只想用的话,就不用看源码,只要看interface里方法的用法就可以了。
      

  4.   

    使用接口的一种方法是,用一个以实现该接口的类,来定义一个接口如:
    Collection c = new ArrayList();
    c.(Arraylist中实Collection中的抽象方法)那这里说的Enumerator又是怎么样的呢?
      

  5.   

    源码就在那儿摆着呢,如果你是不知道匿名类是怎么回事的话,随便找本java书看看,或者在网上查查。