public final class Result<T>
extends java.lang.Object
The outcome of an operation is stored as a success or failure result and does not terminate the processing. The result can be used to determine what to do next.
Example usage:
public boolean carryOutTask() {
Result result = doProcessing();
if (result.isSuccess()) {
return true;
}
return false;
}
private Result doProcessing() {
try {
callAnOperation();
return Result.success("my success data");
} catch (Exception exception) {
return Result.failure(exception);
}
}
| Modifier and Type | Method and Description |
|---|---|
static <T> Result<T> |
failure(java.util.function.Supplier<java.lang.Exception> exceptionSupplier)
Create a failure Result object from an exception supplier.
|
T |
getData()
Returns underlying data stored when the result is a success.
|
java.lang.Exception |
getException()
Get the failure exception.
|
boolean |
isSuccess()
Check if a success result.
|
static <T> Result<T> |
success(T data)
Create a success Result object.
|
public static <T> Result<T> success(T data)
T - the object typedata - the success datapublic static <T> Result<T> failure(java.util.function.Supplier<java.lang.Exception> exceptionSupplier)
T - the object typeexceptionSupplier - the supplierpublic boolean isSuccess()
public T getData()
public java.lang.Exception getException()