- Learn Kotlin Programming(Second Edition)
- Stephen Samuel Stefan Bocutiu
- 82字
- 2021-06-24 14:13:30
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") } }
推薦閱讀
- Visual Studio 2012 Cookbook
- Android Jetpack開(kāi)發(fā):原理解析與應(yīng)用實(shí)戰(zhàn)
- 技術(shù)領(lǐng)導(dǎo)力:程序員如何才能帶團(tuán)隊(duì)
- Apache Spark 2 for Beginners
- Podman實(shí)戰(zhàn)
- GameMaker Programming By Example
- JavaCAPS基礎(chǔ)、應(yīng)用與案例
- Lighttpd源碼分析
- Unity 3D/2D移動(dòng)開(kāi)發(fā)實(shí)戰(zhàn)教程
- Hands-On Full Stack Development with Spring Boot 2.0 and React
- Elasticsearch Essentials
- Instant Automapper
- 從零開(kāi)始學(xué)Selenium自動(dòng)化測(cè)試:基于Python:視頻教學(xué)版
- Xamarin Cross-Platform Development Cookbook
- Access數(shù)據(jù)庫(kù)應(yīng)用教程(2010版)