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

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.

主站蜘蛛池模板: 保定市| 克山县| 磐安县| 离岛区| 土默特右旗| 甘洛县| 正安县| 广元市| 蒲城县| 姚安县| 伽师县| 四平市| 富川| 锦屏县| 昆明市| 隆子县| 延川县| 蕲春县| 尤溪县| 长岛县| 云梦县| 鄂尔多斯市| 会昌县| 清徐县| 简阳市| 邹平县| 乌海市| 西林县| 秦皇岛市| 神池县| 新昌县| 揭西县| 满城县| 右玉县| 竹山县| 伊宁市| 东宁县| 象州县| 泾阳县| 原平市| 淮阳县|