The
NullCheck
class provides functions for performing terse null-checks. The intention is to perform
null checking inside constructors and on the
boundaries of public interfaces. The rationale for the existence of the
null checks at all is that although
variables can be marked
@NonNull
and tools can statically indicate where a
null
value has been passed where a non-
null
value is expected, many programmers do not use these tools. If programmers
are not using these tools, then they are free to pass
null wherever they want - the language
does not prevent it. It is better that checks occur on the boundaries
of classes and interfaces where problems can be caught at an early stage
rather than the code crashing at arbitrary locations
because a
null value worked its way into
the program where one was not expected.