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

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.

主站蜘蛛池模板: 泸溪县| 宜川县| 八宿县| 通道| 雅安市| 宜宾县| 文山县| 凤冈县| 浦县| 嘉义市| 潜江市| 隆林| 兰溪市| 如东县| 竹山县| 巴青县| 噶尔县| 曲麻莱县| 郎溪县| 庄河市| 杂多县| 大英县| 尚志市| 辽中县| 拉孜县| 延寿县| 绍兴市| 新竹县| 灵璧县| 大关县| 九江市| 中西区| 涡阳县| 瓦房店市| 禹州市| 藁城市| 东方市| 理塘县| 婺源县| 政和县| 莎车县|