I personally use check
/checkNotNull
when I check the state of the program at the start of functions.
It’s documentation states:
Signals that a method has been invoked at an illegal or inappropriate time. In other words, the Java environment or Java application is not in an appropriate state for the requested operation.
As an alternative Kotlin has require
/requireNotNull
which throws an IllegalArgumentException. And you can use assert
or !!
inside of a function to check the function is working correctly. I would personally prefer assertNotNull
but it does not exist.