Try needs a factory method to accept units of work returning nothing, i.e. void.
Try.of(CheckedSupplier) and Try.of(CheckedRunnable) would be ambiguous regarding Try.of(() -> { throw new RuntimeException(); }).
Therefore the new factory method is named Try.run(CheckedRunnable).
The return value of Try.run(...) is Try<Void>. In the case of a Success<Void>, the get() will return null, signaling the absence of a value.
We could introduce a new type Try.Nothing extends Try.Success<Void> - but I currently not see any benefits. The result of a 'Try' can be either a success or a failure but not nothing at all.
So, is there a way to have Try.of with void methods - something like:
Try.of(() -> SomeClassWithVoidMethodThrowingAnException::method);
or explicitly:
`Try.
@zerkowsm Try.run(SomeClassWithVoidMethodThrowingAnException::method) is your friend
Most helpful comment
@zerkowsm
Try.run(SomeClassWithVoidMethodThrowingAnException::method)is your friend