Non-Null Assertion Operator

This lesson introduces the non-null assertion operator and discuss when it is ok to use it.

Overview

So far, we haven’t talked about how to fix the kind of errors that are triggered by strict null checks. The reason I haven’t mentioned a non-null assertion operator is that you shouldn’t be using it unless you have a very good reason to do so.

Non-null assertion operators are simply a way of telling the compiler, trust me, I’m absolutely sure that this optional value is in fact never empty. Syntactically, you can express this by postfixing the optional value with a ! character.

Get hands-on with 1200+ tech skills courses.