Bikeshed-ish issue: Optional
David M. Lloyd
david.lloyd at redhat.com
Thu Mar 3 03:42:05 UTC 2016
I notice that Jigsaw is making arguably excessive use of Optional.
Reinier Zwitzerloot  quoted Brian Goetz about this topic; the full
quote  is as follows:
"Of course, people will do what they want. But we did have a clear
intention when adding this feature, and it was not to be a general
purpose Maybe or Some type, as much as many people would have liked us
to do so. Our intention was to provide a limited mechanism for library
method return types where there needed to be a clear way to represent
"no result", and using null for such was overwhelmingly likely to cause
"For example, you probably should never use it for something that
returns an array of results, or a list of results; instead return an
empty array or list. You should almost never use it as a field of
something or a method parameter.
"I think routinely using it as a return value for getters would
definitely be over-use.
"There's nothing wrong with Optional that it should be avoided, it's
just not what many people wish it were, and accordingly we were fairly
concerned about the risk of zealous over-use."
Incidentally  is also the go-to reference when people have questions
about Optional<> in the ##java IRC channel on irc.freenode.net.
More information about the jpms-spec-experts