JEP 269: Convenience Factory Methods for Collections
forax at univ-mlv.fr
Wed Oct 7 12:49:35 UTC 2015
The current guideline seems to be that new collections introduced after Java 4 should not allow null.
ArrayDeque is an example of such collections.
This proposal introduces new static methods on both interfaces and implementations.
Interface static methods use new immutable collections, if those doesn't support null, a user can easily switch to the static method on one of the corresponding implementation class. By example, instead of using List.of (null), one can use ArrayList.of (null).
That's why i think it's fine to not allow null in new immutable collections.
Le 7 octobre 2015 02:13:30 CEST, Stuart Marks <stuart.marks at oracle.com> a écrit :
>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
>>> do this for an actual reason: a negative result is meaningfully
>>> from no result. This is addressed in our Optional javadoc .
>> mapped-to-absent means that you know the keys you are waiting for, so
>you can store them in an external set (list, etc) and enjoy
>implementations like EnumMap or the couple JSObject/HiddenClass you
>> Using Optional for that seem inefficient.
>Indeed, the Optional docs that Kevin linked to themselves have links to
>pages that describe techniques for avoiding use of nulls and Optionals
>such as this. Nonetheless, as Kevin points out, there are 1,800 such
>Google's code base.
>And personally, as a matter of style, I dislike using Optional in
>My question is, is this enough of a problem that we should allow nulls
>collections? I would prefer not to do this, but if there is evidence
>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
More information about the core-libs-dev