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

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") 
      } 
    } 
主站蜘蛛池模板: 镇沅| 青海省| 抚宁县| 赣榆县| 广德县| 洪洞县| 保山市| 舞阳县| 宁武县| 天水市| 普兰县| 恩施市| 龙州县| 南安市| 澄迈县| 神池县| 平阴县| 昭觉县| 通河县| 康保县| 靖西县| 灯塔市| 遂宁市| 望江县| 靖州| 图们市| 宾阳县| 白朗县| 延川县| 恩施市| 荆门市| 德安县| 博白县| 甘泉县| 名山县| 开江县| 阳谷县| 额尔古纳市| 杨浦区| 博野县| 丰都县|