当表达式中删除Kotlin的中断
如何在不破坏表达式的情况下写入kotlin中的表达式? 在Java中,我们可以这样做。
int x = 3; switch (x){ case 1: System.out.println("1"); case 2: System.out.println("2"); case 3: System.out.println("3"); // 3 will be printed case 4: System.out.println("4"); // 4 will be printed }
结果:
3
4
我怎样才能达到这样的效果?
目前使用Kotlin实现Java switch
语句的下翻结构是不可能的。
解决方法:
val x = 3 if (x <= 1) println("1") if (x <= 2) println("2") if (x <= 3) println("3") if (x <= 4) println("4")
@yole :
我们有一个暂时的计划,以支持在支持fallthrough语句中的continue关键字。 不过,它并不是针对任何特定的Kotlin版本。