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

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.

主站蜘蛛池模板: 乐亭县| 扶余县| 大洼县| 姚安县| 两当县| 同江市| 乌鲁木齐市| 永丰县| 永兴县| 土默特左旗| 黔东| 长兴县| 东明县| 西畴县| 锡林浩特市| 噶尔县| 利津县| 普安县| 襄城县| 林芝县| 六安市| 元氏县| 保山市| 长沙县| 佛坪县| 乌鲁木齐县| 平和县| 鸡西市| 将乐县| 五指山市| 陈巴尔虎旗| 通海县| 周宁县| 修水县| 奉贤区| 且末县| 惠水县| 嵩明县| 汉阴县| 尚志市| 鹤峰县|