What is the Kotlin double-bang (!!) operator?

Technology CommunityCategory: KotlinWhat is the Kotlin double-bang (!!) operator?
VietMX Staff asked 3 years ago

The not-null assertion operator !! converts any value to a non-null type and throws a KotlinNullPointerException exception if the value is null.

Consider:

fun main(args: Array<String>) {
    var email: String?
    email = null
    println(email!!)
}

This operator should be used in cases where the developer is guaranteeing – it allows you to be 100% sure that its value is not null.