Should you assert not null with the assert statement in production code? [closed]
Use Objects.requireNonNull(Object) for that. Checks that the specified object reference is not null. This method is designed primarily for doing parameter validation in methods and constructors, […] In your case that would be: public void useObject(CustomObject customObject) { object = customObject.getObject(); Objects.requireNonNull(object); // throws NPE if object is null // do stuff with object } … Read more