本文共 351 字,大约阅读时间需要 1 分钟。
最近遇到了这个报错,报错的原因在于调用了ArrayList的sort方法,查看代码之后发现,sort方法也会改变modCount的值。后续需要注意。
@Override@SuppressWarnings("unchecked")public void sort(Comparator c) { final int expectedModCount = modCount; Arrays.sort((E[]) elementData, 0, size, c); if (modCount != expectedModCount) { throw new ConcurrentModificationException(); } modCount++;}
转载地址:http://wlyai.baihongyu.com/