什么是 Kotlin double-bang (!!) 运算符? [英] What is the Kotlin double-bang (!!) operator?
本文介绍了什么是 Kotlin double-bang (!!) 运算符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 Android Studio 将 Java 转换为 Kotlin.在实例变量之后我得到了双重打击.什么是双爆炸,更重要的是,这在哪里记录?
I'm converting Java to Kotlin with Android Studio. I get double bang after the instance variable. What is the double bang and more importantly where is this documented?
mMap!!.addMarker(MarkerOptions().position(london).title("Marker in London"))
推荐答案
这是不安全的可空类型 (T?
) 转换为不可空类型 (T
),如果值为 null
,!!
将抛出 NullPointerException
.
This is unsafe nullable type (T?
) conversion to a non-nullable type (T
),
!!
will throw NullPointerException
if the value is null
.
此处 以及 Kotlin 的方法空安全.
It is documented here along with Kotlin means of null-safety.
这篇关于什么是 Kotlin double-bang (!!) 运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文