Proposal: Collection Literals

Mark Thornton mthornton at optrak.co.uk
Tue Mar 31 00:56:10 PDT 2009


Joshua Bloch wrote:
> The method invocations (Collections.unmodifiableList(Arrays.asList) are just
> noise. With list literals, it would look like this:
>
>     final List<Integer> piDigits = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9];
>
>
> By substituting curly braces for the square brackets, you get a set literal
> in place of a list:
>
>
>     final Set<Integer> primes = { 2, 7, 31, 127, 8191, 131071, 524287 };
>   
Would it be possible to infer the type of the RHS from the left (and 
thus also avoid Neal's issue with generics). You could then use {} for 
both lists and sets, and not need the odd syntax for an empty map.

Thus:

List<Integer> emptyList = {};
Set<Integer> emptySet = {};
Map<String, String> emptyMap = {};

Regards,
Mark Thornton




More information about the coin-dev mailing list