See: Description
| Class | Description |
|---|---|
| Results |
This class consists exclusively of static methods that return
Result instances. |
There are several ways to create result objects.
A successful result contains a non-null value produced by an operation when everything works as intended.
On the other hand, a failed result holds a value representing the problem that prevented the operation from completing.
When we need to create results that depend on a possibly null value. If the first argument is null, then the
second one will be used to create a failed result. The second argument can be either a failure value or a function
that produces a failure value.
We can also create results that depend on an Optional value. If the first argument is an
empty optional, then the second one will be used to create a failed result. The second argument can be a
Supplier too.
Finally, if we have a task that may either return a success value or throw an exception, we can encapsulate it as a result so we don't need to use a try-catch block.
Results,
Result