官术网_书友最值得收藏!

The when without argument

The second form of when is used without an argument, and is a drop-in replacement for if...else clauses. This can sometimes result in clearer code, especially if many of the conditions are simple comparisons. The following example shows a way of writing the same code using when:

    fun whenWithoutArgs(x: Int, y: Int) { 
      when { 
        x < y -> println("x is less than y") 
        x > y -> println("X is greater than y") 
        else -> println("X must equal y") 
      } 
    } 
主站蜘蛛池模板: 鹤峰县| 武汉市| 樟树市| 仙桃市| 普兰店市| 康保县| 灵璧县| 南昌县| 龙胜| 桓仁| 闽清县| 兴城市| 曲麻莱县| 大港区| 嘉定区| 大石桥市| 固始县| 大洼县| 方山县| 绥宁县| 霞浦县| 沾化县| 乌拉特后旗| 东乌珠穆沁旗| 腾冲县| 中阳县| 河津市| 长治市| 左云县| 公安县| 扶沟县| 砀山县| 射阳县| 卓资县| 涟水县| 长海县| 沙河市| SHOW| 尼木县| 阜新| 从化市|