Kotlin 中 switch 写法
生活随笔
收集整理的這篇文章主要介紹了
Kotlin 中 switch 写法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在Kotlin 中并沒有switch 操作符?, 取而代之的是when?
java的寫法:
int i= 5;switch (i){case 5:System.out.print("5");break;case 4:System.out.print("4");break;case 3:System.out.print("3");break;case 2:System.out.print("2");break;case 1:System.out.print("1");break;}
Kotlin 寫法:
val i = 5when (i) {5 -> print("5")4 -> print("4")3 -> print("3")2 -> print("2")1 -> print("1")}
?
總結
以上是生活随笔為你收集整理的Kotlin 中 switch 写法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 梅花龙表的龙是谁画的啊?
- 下一篇: Kotlin 继承