Assert.java add support
like this:
int a = .......;
Assert.state(a > 0, () -> new RuntimeException("must > 0"));
public static void state(boolean expression, Supplier<RuntimeException> exceptionSupplier) {
if (!expression) {
throw exceptionSupplier.get();
}
}
Comment From: jhoeller
Assert.state
is really meant to throw an IllegalStateException
, hence the name of the method. In general, we should rather refrain from adding further methods to Assert
which is primarily meant as a utility for internal use within the framework.
If you'd like to have such a method, you should rather add it to a custom Assert
class in your own codebase instead.