JEP 186: Collection Literals

Klaus Malorny Klaus.Malorny at
Tue Jan 14 09:02:19 PST 2014

On 14.01.2014 17:33, Nick Williams wrote:
 > I think we should also try to keep the Java Unified Expression Language in
 > mind while designing this. Java EE 7 added lambda expressions to JUEL. Can
 > you imagine how confusing it would have been if they had defined a different
 > lambda syntax than Java 8? They didn't, though. They made the syntax mirror
 > Java 8 lambdas.
 > JUEL also has collection literals now, and I think it would be foolish to
 > define a literal syntax different than that defined in JUEL. It will make
 > developers' lives more difficult. The JUEL syntax is simple and I think it
 > would work perfectly in Java as well:
 > List: [ 1, 2, 3 ] Set: { 1, 2, 3 } Map: { "one" : 1, "two" : 2, "three" : 3
 > }
 > If we, for example, make Lists use curly braces in Java when they already use
 > square brackets in JUEL, that would be unfortunate.
 > Nick


if I may add my two cents: I have solved the problem for me by

- having a static setOf (...) method to construct sets, which
   is imported via static import if need be
- having a static mapOf (key, value) method which is the start
   of a call chain, ending with map (), which returns the constructed

   e.g. Map<String, Integer> map = mapOf ("one", 1).put ("two", 2).
          put ("three", 3).map ();

Overloaded and alternative methods allow me to create unmodifiable sets and 
maps, including EnumMaps, also to perform some additional checks for EnumMaps 
(e.g. whether all keys occur). Similar could be done for lists, of course.

So while I do not dislike collection literals, I just want to point out that the 
keyboard typing benefit isn't that great IMHO.



More information about the lambda-dev mailing list