- Learn Kotlin Programming(Second Edition)
- Stephen Samuel Stefan Bocutiu
- 109字
- 2021-06-24 14:13:30
The when expression
The classic switch statement is supported in many languages, including C, C++, and Java, but it is rather restrictive. At the same time, the functional programming concept of pattern matching has become more mainstream. Kotlin blends the two, and offers when, a more powerful alternative to switch while not going quite as far as full pattern matching.
There are two forms of when. The first is similar to switch, accepting an argument, with a series of conditions, each of which is checked, in turn, against the value. The second is without an argument and is used as a replacement for a series of if...else conditions.
推薦閱讀
- WildFly:New Features
- Android Jetpack開發:原理解析與應用實戰
- 前端跨界開發指南:JavaScript工具庫原理解析與實戰
- PHP程序設計(慕課版)
- C語言程序設計同步訓練與上機指導(第三版)
- Asynchronous Android Programming(Second Edition)
- Visual C++開發入行真功夫
- 計算機應用基礎實踐教程
- Creating Stunning Dashboards with QlikView
- Procedural Content Generation for C++ Game Development
- Xamarin Blueprints
- Java7程序設計入門經典
- R語言數據挖掘:實用項目解析
- Visual C++程序設計全程指南
- Mastering JavaScript Promises