- 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 Basic程序設計上機實驗教程
- Python入門很簡單
- Visual C++數字圖像模式識別技術詳解
- The Data Visualization Workshop
- Mastering KnockoutJS
- 快速念咒:MySQL入門指南與進階實戰
- Apache Spark 2.x for Java Developers
- 利用Python進行數據分析
- Visual Basic程序設計上機實驗教程
- Service Mesh實戰:基于Linkerd和Kubernetes的微服務實踐
- Android移動開發案例教程:基于Android Studio開發環境
- Frank Kane's Taming Big Data with Apache Spark and Python
- UNIX Linux程序設計教程
- 代替VBA!用Python輕松實現Excel編程
- Python Interviews