Java 表达式时删除Kotlin中的中断
当表达式在kotlin中时,如何在不中断表达式的情况下编写?在Java中,我们可以这样做Java 表达式时删除Kotlin中的中断,java,switch-statement,kotlin,Java,Switch Statement,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.prin
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开关的直通结构
解决方法:
val x = 3
if (x <= 1) println("1")
if (x <= 2) println("2")
if (x <= 3) println("3")
if (x <= 4) println("4")
valx=3
if(x)