为什么说Vector是同步的?方法没有synchronized关键字啊?怎么还说它是同步的呢?

解决方案 »

  1.   

    你去看看Vector的源代码,他的方法都是
    public synchronized Object add(Object obj)
    这个样子的?还有,哪个家伙告诉你 、,方法没有synchronized关键字???
      

  2.   

    比如这样的:
    add
    public boolean add(E o)Appends the specified element to the end of this Vector. Specified by:
    add in interface Collection<E>
    Specified by:
    add in interface List<E>
    Overrides:
    add in class AbstractList<E>
    Parameters:
    o - element to be appended to this Vector. 
    Returns:
    true (as per the general contract of Collection.add).
    Since: 
    1.2
    在java那个网站看的http://java.sun.com/j2se/1.5.0/docs/api/
    确实不知道怎么看哪里写synchronized不要取笑:) 
      

  3.   

    这个是源代码,你自己看吧    /**
         * Appends the specified element to the end of this Vector.
         *
         * @param o element to be appended to this Vector.
         * @return true (as per the general contract of Collection.add).
         * @since 1.2
         */
        public synchronized boolean add(E o) {
    modCount++;
    ensureCapacityHelper(elementCount + 1);
    elementData[elementCount++] = o;
            return true;
        }
      

  4.   

    呵呵 楼主没看仔细
    Specified   by: 
    add   in   interface   Collection <E> 
    这句话的意思是说Collection 接口有add方法 因为vector实现了collection接口
    所以vector也要指定add方法。(翻译真困难)
      

  5.   

    承上 补充
    所以add        in       interface       Collection   <E>
    这一句并不是方法的声明。而是一个说明性句子。