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 [1] quoted Brian Goetz about this topic; the full
quote [2] 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
errors.
"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 [1] is also the go-to reference when people have questions
about Optional<> in the ##java IRC channel on irc.freenode.net.
[1]
https://www.voxxed.com/blog/2015/01/embracing-void-6-refined-tricks-dealing-nulls-java/
[2]
https://stackoverflow.com/questions/26327957/should-java-8-getters-return-optional-type/26328555#26328555
--
- DML
More information about the jpms-spec-experts
mailing list