Is it possibile to have an java.util.Optional which is evaluated only if needed?
I need to pass an Optional to a method (of an API that I cannot change), and this method may or may not make use the value of that Optional. Since the value is computed by a heavy operation, I'd like to compute that value only when (and if) it is needed, e.g. calling get(), orElseGet(), ifPresent(), etc.
Something like Optional.ofLazy(Supplier<T> computeValue).