gpt4 book ai didi

Groovy 中的 java.util.ConcurrentModificationException

转载 作者:塔克拉玛干 更新时间:2023-11-01 23:08:36 24 4
gpt4 key购买 nike

我有这段代码:

       void remove(){
boolean allowRemove = false;
violations.each{
if(it.selected) allowRemove = true;
}
if(!allowRemove) throw new Exception("No item selected!");
if(allowRemove){
def templist = violations;
templist.each{ if(it.selected) templist.remove(it) }
violations = templist;
tableHandler.reload();
}
}

每次执行此代码时,我的应用程序都会抛出错误:java.util.ConcurrentModificationException。我找到了关于如何使用 IteratorJava 中解决此问题的答案。但我不知道如何在 Groovy 中对其进行编码。有什么想法吗?

最佳答案

使用 templist.removeAll{it.selected}

编辑:这适用于 Groovy 1.7.4:

class Test {

static void main(String[] args) {
def c = [1, 2, 3, 4, 5]
c.removeAll { it % 2 == 0 }
println c
}

关于Groovy 中的 java.util.ConcurrentModificationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35076317/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com