The function requireNotNull() is a great tool to use in your arsenal. The requireNotNull() is very similar to calling variable != null:
That != null example is very similar to this requireNotNull() example:
all the requireNotNull does is if the variable is not null, then run this piece of code. But it can also return the variable if it’s null, and also throw an exception when it’s null.
The app would crash at that code because when the variable is null. At requireNotNull, it’ll throw an exception which is called IllegalArgumentException, which crashes the app.
We have a working example here: