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

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.

主站蜘蛛池模板: 鸡泽县| 紫金县| 新泰市| 屏南县| 华蓥市| 霍山县| 襄汾县| 高雄市| 金川县| 郑州市| 福海县| 梓潼县| 安福县| 彩票| 封开县| 万全县| 阿坝| 阳信县| 建始县| 五寨县| 普定县| 磐石市| 鹤山市| 大英县| 台山市| 太康县| 毕节市| 青海省| 禄劝| 双辽市| 固始县| 博客| 胶州市| 清新县| 阜阳市| 顺昌县| 双鸭山市| 义马市| 栖霞市| 天长市| 朝阳市|