AbstractCollection:提供集合最大實現,子類必須實現 size() 和 iterator()。AbstractList:提供順序表最大實現,子類需實現 get(int index),迭代器依賴它。modCount 記錄修改次數,迭代器維護 expectedModCount。ConcurrentModificationException。modCount 用 volatile 修飾,保證多線程可見性。modCount 即線程不安全,建議使用迭代器而非直接操作。addAll 為深拷貝(調用 Arrays.copyOf → System.arraycopy)。length 決定,非 size。ensureCapacity 統一入口。System.arraycopy。null,便於垃圾回收。fastRemove(index) 跳過二次比較。
原文鏈接:https://blog.zswlib.com/2016/10/26/jdk%e9%a1%ba%e5%ba%8f%e8%a1%a8%e7%ac%94%e8%ae%b0/