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?
Double-bang operator is an excellent option for fans of NullPointerException
(or NPE for short).
The not-null assertion operator
!!
converts any value to a non-null type and throws an exception if the value is null.
val nonNull = a!!.length
So you can write a!!
, and this will return a non-null value of a
(a String
here for example) or throw an NPE if a
is null.
If you want an NPE, you can have it, but you have to ask for it explicitly. This operator should be used in cases where the developer is guaranteeing – the value will never be null.