Skip to content

Commit

Permalink
Update java8
Browse files Browse the repository at this point in the history
  • Loading branch information
rushercm authored Feb 25, 2019
1 parent ed1533d commit c102031
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions java8
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,10 @@ copyonwrite:弱一致性(add和get时,若有修改,不能保证修改的
-->内部类用final修饰局部变量,不共享,也是copy一份
-->CAS保证原子性:for (;;) {atomicI.compareAndSet(i, ++i);}多次循环直到成功break

HashMap:高位取模 int index = (tab.length - 1) & hash;
-->数组的长度按规定一定是2的幂(2的n次方)。
-->因此,数组的长度的二进制形式是:10000…000, 1后面有一堆0。tab.length - 1 的二进制形式就是01111…111, 0后面有一堆1。
最高位是0, 和hash值相“与”,结果值一定不会比数组的长度值大,因此也就不会发生数组越界.



0 comments on commit c102031

Please sign in to comment.