我想break
在嵌套的forEach循环中进行类似操作,以过滤searchView中的数据(如果数据内容在我的搜索中包含任何单词)。
val filtered = mutableListOf() rawDataList.forEach {data -> text.split(' ').forEach { word -> if (data.content.contains(word, ignoreCase = true)) { filtered.add(data) return@forEach // **There is more than one label with such a name in this scope** } } }
我的情况下是否存在优雅的解决方案?
如果您遇到此错误,并且无法使用内置函数修复该错误,则可以通过name@
在块之前添加,将自定义标签应用于lambda :
rawDataList.forEach outer@{data -> text.split(' ').forEach { word -> if (data.content.contains(word, ignoreCase = true)) { filtered.add(data) return@outer } } }