Forget Optional<T>, adopt Try<T>?
paul.sandoz at oracle.com
Tue Jun 4 01:21:48 PDT 2013
On Jun 4, 2013, at 6:21 AM, Zhong Yu <zhong.j.yu at gmail.com> wrote:
> I'm thinking that if we have something like scala's Try<T>, it'll
> express APIs' intentions better than Optional<T>.
> Some people view Optional as a collection of either 0 or 1 element.
> That doesn't seem to be what an API author wants to express by
> returning an Optional. The actual intention is that, either the action
> succeeds with a value (not a collection of!), or it fails (with an
> unspecified or implied reason).
The intention is whether the terminal operation returned a result or not, perhaps because the stream is empty or because the given the search criterea no result matched (although it is only the former which occurs at the moment), rather than because of some error specified or otherwise.
I like the concept of Try but in the context of a replacement for Optional i think it just muddies the waters.
More information about the lambda-dev