- 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.
推薦閱讀
- 軟件項(xiàng)目估算
- Python程序設(shè)計(jì)教程(第2版)
- CockroachDB權(quán)威指南
- R語言經(jīng)典實(shí)例(原書第2版)
- 騰訊iOS測試實(shí)踐
- Flux Architecture
- Microsoft Azure Storage Essentials
- C語言開發(fā)基礎(chǔ)教程(Dev-C++)(第2版)
- 零基礎(chǔ)學(xué)Kotlin之Android項(xiàng)目開發(fā)實(shí)戰(zhàn)
- Azure Serverless Computing Cookbook
- Learning Splunk Web Framework
- 計(jì)算語言學(xué)導(dǎo)論
- 3ds Max 2018從入門到精通
- Android智能手機(jī)APP界面設(shè)計(jì)實(shí)戰(zhàn)教程
- ArcPy and ArcGIS(Second Edition)