0Pricing
Kotlin Academy · Lesson

The !! Operator

Force non-null and its risks.

Forcing Non-Null

Sometimes you are certain a nullable value is not null, but the compiler still complains.

The not-null assertion operator !! tells the compiler to trust you and treat the value as non-null.

Basic Usage

Adding !! converts a nullable type to its non-null counterpart.

If the value really is non-null, the code works exactly like a normal call.

fun main() {
    val name: String? = "Kotlin"
    println(name!!.length)
}

All lessons in this course

  1. Nullable and Non-Null Types
  2. Safe Calls and Elvis
  3. The !! Operator
  4. Platform Types
← Back to Kotlin Academy