public final class Requires extends Object
| 限定符和类型 | 方法和说明 |
|---|---|
static <T> T |
requireNonNull(T obj)
Checks that the specified object reference is not
null. |
static <T> T |
requireNonNull(T obj,
String message)
Checks that the specified object reference is not
null and
throws a customized NullPointerException if it is. |
static void |
requireTrue(boolean expression)
Ensures the truth of an expression involving one or more parameters
to the calling method.
|
static void |
requireTrue(boolean expression,
Object message)
Ensures the truth of an expression involving one or more parameters
to the calling method.
|
static void |
requireTrue(boolean expression,
String fmt,
Object... args)
Ensures the truth of an expression involving one or more parameters
to the calling method.
|
public static <T> T requireNonNull(T obj)
null.T - the type of the referenceobj - the object reference to check for nullityobj if not nullNullPointerException - if obj is nullpublic static <T> T requireNonNull(T obj,
String message)
null and
throws a customized NullPointerException if it is.T - the type of the referenceobj - the object reference to check for nullitymessage - detail message to be used in the event that a NullPointerException is thrownobj if not nullNullPointerException - if obj is nullpublic static void requireTrue(boolean expression)
expression - a boolean expressionIllegalArgumentException - if expression is falsepublic static void requireTrue(boolean expression,
Object message)
expression - a boolean expressionmessage - the exception message to use if the check fails;
will be converted to a string using
String.valueOf(Object)IllegalArgumentException - if expression is falsepublic static void requireTrue(boolean expression,
String fmt,
Object... args)
expression - a boolean expressionfmt - the exception message with format stringargs - arguments referenced by the format specifiers in the format
stringIllegalArgumentException - if expression is falseCopyright © 2021. All rights reserved.