java.lang.Object
io.hotmoka.exceptions.Objects
A collection of run-time checks on objects, with parametric exception type.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T,E extends Exception>
TrequireNonNull(T obj, ExceptionSupplier<? extends E> onNull) Checks that the specified object reference is notnull.static <T,E extends Exception>
TrequireNonNull(T obj, String message, ExceptionSupplier<? extends E> onNull) Checks that the specified object reference is notnull.
-
Constructor Details
-
Objects
public Objects()
-
-
Method Details
-
requireNonNull
public static <T,E extends Exception> T requireNonNull(T obj, ExceptionSupplier<? extends E> onNull) throws E Checks that the specified object reference is notnull. This method is designed primarily for doing parameter validation in methods and constructors, as demonstrated below:public Foo(Bar bar) { this.bar = Objects.requireNonNull(bar, IllegalArgumentException::new); }- Type Parameters:
T- the type of the referenceE- the type of the exception thrown ifobjisnull- Parameters:
obj- the object reference to check for nullityonNull- the generator of the exception thrown ifobjisnull- Returns:
objif notnull- Throws:
E- ifobjisnull
-
requireNonNull
public static <T,E extends Exception> T requireNonNull(T obj, String message, ExceptionSupplier<? extends E> onNull) throws E Checks that the specified object reference is notnull. This method is designed primarily for doing parameter validation in methods and constructors, as demonstrated below:public Foo(Bar bar) { this.bar = Objects.requireNonNull(bar, "bar cannot be null", IllegalArgumentException::new); }- Type Parameters:
T- the type of the referenceE- the type of the exception thrown ifobjisnull- Parameters:
obj- the object reference to check for nullitymessage- the message of the exception thrown ifobjisnullonNull- the generator of the exception thrown ifobjisnull- Returns:
objif notnull- Throws:
E- ifobjisnull
-