172.16.0.151_20200910-陈政平

问题

int x = 0 ; // 第一个元素的索引对应零
        Node<E> node = first ; // 第一个元素的索引对应零
        while( node != null ) {
            if( x == index ) {
                return node.item ;
            }
            node = node.next ;
            x++ ;
        }

node是一个存放元素的位置,并非一个元素,node里面不为空时才进行下一步 if 条件判断。

public V put( K key , V value ) {
        System.out.println(counter);
        for( int i = 0 ; i < counter ; i++ ) {
            ItlaobingEntry<K,V> e = table[i] ;
            if( e.getKey() == key || e.getKey().equals( key ) ) {
                V oldValue = e.setValue( value );
                return oldValue ;
            }
        }
        ItlaobingEntry<K,V> entry = new ItlaobingEntry<>(key,value);
        table[ counter ] = entry ;
        counter++;
        return null ;
    }

if( e.getKey() == key || e.getKey().equals( key ) ) {
V oldValue = e.setValue( value );
return oldValue ;
}

这里的oldValue是 被覆盖后的新值,而

public VTYPE setValue(VTYPE value) {
VTYPE oldValue = this.value ;
this.value = value;
return oldValue ;
}

中的 return oldValue ; 返回的是覆盖之前的旧值,是第二段代码中调用 e.setValue( value ) 时所返回的值;

吐槽

标签


© 2021 成都云创动力科技有限公司 蜀ICP备20006351号-1