Non-null assertion

There may be situations in which a null safe call is not how you want to handle null. Another option is to use a non-null assertion call on the nullable variable. This will throw NullPointerException if the variable is null. This might be desirable if you're parsing input parameters and your program can't run without them. We can see an example of this in the following snippet:

fun parseArgs(args: Array<String>?) {
val argCount = args!!.size // throw NPE if 'args' is null
}

In situations like this, it may then be desirable to fail quickly rather than providing a default value.

If you use a non-null assertion call on a variable and then use that variable again after the call, the compiler will SmartCast the variable to a non-null type and you can omit any further safe or non-null assertion calls.