JEP 186: Collection Literals

Per Bothner per at
Thu Jan 16 08:49:15 PST 2014

On 01/16/2014 05:11 AM, Remi Forax wrote:
> At least, in term of documentation, this kind of Builder is better, you
> can find it easily because it's a constructor of the Collection
> implementation you want to create.

Another advantage of Builder is that it's more flexible,
For example assume:
   T1 v1 = #{3, 4, 5}                    // list/collection
   T2 v2 = #[\(reg *\)exp]               // regular expression
   T3 v3 = #[10m^2/s]                    // quantity
   T4 v4 = #[The result is: ]{result}    // hybrid

The latter could be compiled into:
   T4 v4 = T4.builder()
             .addText("The result is: ")

If we have a map/pair syntax, an entry could be compiled
to a call to addEntry(key, value).

In addition addAll is useful for translating a "splice"
	--Per Bothner
per at

More information about the lambda-dev mailing list