Not-Null Assertion (!!) (Kotlin)
The !! operator forcibly converts a nullable value to its non-null type, throwing a NullPointerException at runtime if the value actually is null. Use it only when you're certain it isn't null.
Kotlin
Appending !! to a nullable expression (value!!) tells the compiler 'trust me, this is not null'. If you're right, you get a non-null value; if you're wrong, it throws an NPE at that exact line — reintroducing the very crash Kotlin tries to prevent.
It exists as an escape hatch for the rare case where you know more than the compiler, but heavy use of !! is a code smell. Prefer ?. with ?:, an explicit null check (which enables smart casts), or requireNotNull(x) which throws a clearer message.
A useful debugging property: because !! pinpoints the line, an NPE from it is easier to track down than one buried deep in chained calls. Still, treat each !! as a claim you must be able to justify.
Syntax
val length = name!!.length // throws if name is nullExamples
Kotlin
val name: String? = "Kotlin"
val len = name!!.length // safe: we know it's non-null
println(len)Output:
6