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

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") 
      } 
    } 
主站蜘蛛池模板: 乐至县| 罗平县| 喀什市| 鹿邑县| 盐亭县| 阳朔县| 仙游县| 海门市| 外汇| 房产| 申扎县| 荔浦县| 辽宁省| 临夏市| 资中县| 新闻| 常德市| 溧水县| 玛纳斯县| 合山市| 阿城市| 侯马市| 齐河县| 积石山| 左权县| 湄潭县| 茌平县| 汾西县| 吉林省| 梅州市| 福泉市| 大关县| 北辰区| 中阳县| 桐城市| 永吉县| 苍山县| 罗江县| 远安县| 阿合奇县| 博兴县|