Point lambdaification of List/Set/Map

Nick Williams nicholas+openjdk at nicholaswilliams.net
Fri Jul 12 00:00:58 UTC 2013

On Jun 24, 2013, at 10:14 AM, Stephen Colebourne wrote:

> One point lambdaification that I haven't seen mentioned is addition
> static factory methods for the main collection interfaces. (Strictly,
> this proposal is not point lambdaification as it does not involve
> lambdas, but it is very much in the same area).
> I propose adding these static methods:
> Collection.empty()
> Collection.of(T...)
> List.empty()
> List.of(T...)
> Set.empty()
> Set.of(T...)
> Map.empty()
> Map.of(Entry...)
> Map.Entry.of(K, V)
> Each of these methods would return immutable implementations.
> There is a case for extending the methods to Iterator and other
> collection types, however these are the most important.
> These follow the designs of Stream static methods IIRC.
> This library change would remove much of the requirement for the
> "collection literals" change discussed in Project Coin.

In general I really like the idea of these methods and support them, but I wanted to make something clear. This:

Map.of(Map.Entry.of("hello", value1), Map.Entry.of("world", value2), Map.Entry.of("foo", value3), Map.Entry.of("bar", value4))

Is NOT a replacement for this:

{ "hello" : value1, "world" : value2, "foo" : value3, "bar" : value4 }

The former is incredibly more verbose than the latter, and that verbosity is wholly unnecessary. I still support the addition of these methods, and perhaps the future Collection Literals are syntactic sugar for them, but it most certainly does NOT "remove much of the requirement for the 'collection literals' change discussed in Project Coin." Collection literals are still very much desired and lacking, even with these new methods.


More information about the core-libs-dev mailing list