什么是Kotlin双爆炸(!!)运算符? [英] What is the Kotlin double-bang (!!) operator?
本文介绍了什么是Kotlin双爆炸(!!)运算符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用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双爆炸(!!)运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文