JEP 269: Convenience Factory Methods for Collections
stuart.marks at oracle.com
Wed Oct 7 00:13:30 UTC 2015
On 10/3/15 7:16 AM, forax at univ-mlv.fr wrote:
> "Kevin Bourrillion" <kevinb at google.com> wrote:
>> We have ~1800 occurrences of Optional-valued Maps or Caches in Google. They
>> do this for an actual reason: a negative result is meaningfully different
>> from no result. This is addressed in our Optional javadoc .
> Using Optional for that seem inefficient.
Indeed, the Optional docs that Kevin linked to themselves have links to other
pages that describe techniques for avoiding use of nulls and Optionals in cases
such as this. Nonetheless, as Kevin points out, there are 1,800 such usages in
Google's code base.
And personally, as a matter of style, I dislike using Optional in collections.
My question is, is this enough of a problem that we should allow nulls in these
collections? I would prefer not to do this, but if there is evidence that this
would be a mistake, I'd like to hear it.
And if disallowing nulls will cause developers to create things like
Map<K,Optional<V>>, are we ok with that, and are developers ok with that?
More information about the core-libs-dev