标签并不表示forEach中的循环
我从Kotlin的一个循环中继续,但是我从工作室得到警告,标签不表示循环。 有人能告诉我什么是错的语法?
这是代码段
newRooms.forEach roomloop@ { wallRoom: WallRoom -> val index = rooms.indexOf(wallRoom) if(index!=-1) { val room = rooms[index] //get the corresponding room. //check if the last session is same in the room. if(wallRoom.topics.last().fetchSessions().last()==room.topics.last().fetchSessions().last()) { continue@roomloop }
- BottomNavigationView链接到ViewPager,当我设置监听器bottomNavigationView,我必须点击两次执行我所做的
- 无法从匿名类访问外部类
- 如何将Java类转换为Kotlin数据类
- 如何在Android中使用Kotlin动态添加按钮
- Android Studio在Kotlin第二次编译之前不会编译更改
这里标记的lambda表达式是一个函数文字,而不是一个循环。
您不能在这里break
或continue
lambda表达式,因为它独立于for循环。
public inline fun <T> Array<out T>.forEach(action: (T) -> Unit): Unit { for (element in this) action(element) }
您可以使用return
从函数返回。
return@roomloop
请注意,下面的代码段与另一个代码段的行为相同,它们都将打印123
:
arrayOf(1, 2, 3).forEach label@ { print(it) return@label } label@ for (i in arrayOf(1, 2, 3)) { print(i) continue@label }
- 在Kotlin中实例化对象时如何覆盖方法?
- 在Kotlin中使用RXJava地图?
- Android Firebase身份验证:未找到com.google.android.gms.crash和com.google.firebase.auth的本地模块描述符类
- 如何跳过基础包中的retrofit2使用的proguard模型?
- Android Studio – java.io.IOException:无法生成v1签名
- 将Firebase中的数据加载到ExpandableList
- 用Kotlin记录
- 连接检查不工作在Android奥利Kotlin
- 在Android lint检查LinkedHashMap.remove()的错误肯定