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

The (!!) operator

Instead of a null value, the !! operator will throw an NPE:

val result: String = nullableCupcake!!.eat()

If you can deal with an NPE, the !! operator gives you a pretty convenient feature, a free smart cast:

val result: String = nullableCupcake!!.eat()

val length: Int = nullableCupcake.eat().length

If nullableCupcake!!.eat() doesn't throw an NPE, Kotlin will change its type from Cupcake? to Cupcake from the next line and onwards.

主站蜘蛛池模板: 时尚| 手机| 南昌市| 白山市| 高邮市| 施秉县| 大化| 汕尾市| 瑞昌市| 新晃| 凤台县| 开平市| 泉州市| 大冶市| 舒兰市| 武宣县| 白河县| 洛扎县| 龙泉市| 松溪县| 峡江县| 寿阳县| 乐都县| 伊宁市| 宜城市| 垦利县| 裕民县| 定西市| 浮梁县| 吴江市| 农安县| 丽水市| 安福县| 弥渡县| 什邡市| 西乡县| 中牟县| 固始县| 黄山市| 柘城县| 白河县|