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

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") 
      } 
    } 
主站蜘蛛池模板: 西畴县| 鄂托克前旗| 香港 | 泗阳县| 张家界市| 岑溪市| 亚东县| 新和县| 南京市| 太仓市| 察哈| 秦皇岛市| 临夏县| 会泽县| 济宁市| 左贡县| 全州县| 厦门市| 新河县| 白玉县| 来安县| 元谋县| 应城市| 新余市| 额尔古纳市| 喀什市| 资兴市| 海安县| 乐山市| 磐安县| 德庆县| 塔城市| 即墨市| 靖边县| 乌恰县| 高碑店市| 龙山县| 桂林市| 景洪市| 花莲市| 溧阳市|