Force unwrap (!!)

However, often we know that an object is not null at the time of access, but since the type is nullable we have to do the null handling. In such situations, we have a way to insist that a compiler gives whatever value it has with the !! operator: 

    var num: Int? = null    num!!.div(10)

The preceding code will compile, but since we have used !!, the app will crash.

While using !! make sure we are conscious. If we use just it to avoid compiler errors, we may need to deal with a lot of crashes. Use it in this very specific situation.

Get Kotlin Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.