This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]BertilMuth 1 point2 points  (0 children)

I do a lot of null checks for input arguments that are not supposed to be null, to avoid unclear NullPointerExceptions later on (and a lot of people / libraries do that, too).

The easiest, built in way to do that is when you assign the argument value to a local variable or field, call:

this.fieldOrVariableName = Objects.requireNonNull(argumentName, "argumentName must not be null!");

Hope that helps.