Suppose I have a library method like this (very abbreviated):
public static <V> Optional<V> doSomethingWith(Callable<V> callable) {
try {
return Optional.of(callable.call());
} catch (Exception ex) {
// Do something with ex
return Optional.empty();
}
}
And I want to something that doesn't return a value, like:
Library.</*What1*/>doSomethingWith(() -> {
foo();
return /*what2*/;
});
My first instinct for a generic method that doesn't return a value is making the type Void
and returning null
, however because the result gets wrapped in an Optional
this would throw an exception.
What are reasonable placeholders for /*What1*/
and /*what2*/
that don't look totally random like Integer
and 0
?
[edit]
I'm trying to avoid Optional.ofNullable
because empty is used here to indicate that callable.call()
did not complete normally.