Skip to content

Instantly share code, notes, and snippets.

@tadams
Last active January 3, 2016 09:59
Show Gist options
  • Save tadams/8446081 to your computer and use it in GitHub Desktop.
Save tadams/8446081 to your computer and use it in GitHub Desktop.
import static java.util.Objects.requireNonNull;
...
// throws a NullPointerException when null
requireNonNull(employee);
// throws a NullPointerException with a message
requireNonNull(employee, "employee reference is null");
// throws a NullPointerException with a message from a supplier function
requireNonNull(employee, () -> errorMsgProducer.getNullMessage("employee"));
// do paycheck stuff ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment