Improved List initialisation

Matthias Ernst matthias at mernst.org
Wed Sep 12 07:47:57 UTC 2007


On 9/11/07, Richard Warburton <richard.warburton at gmail.com> wrote:
> In java we could get a similarly concise effect, with no hacking in
> syntactic sugar to solve these problems, I am thinking of a syntax
> along the lines of:
>
> List<Integer> intList = new ArrayList<Integer>(1,2,3);

Most welcome!

The one-liner I use is
new ArrayList(Arrays.asList(1,2,3));

but it goes on my nerves.


On a side note, I would be interested in the history of var-args in
this context - in the tiger release we were given var-args and at the
same time shunned away from arrays. Was List considered for varargs?

Nowadays I code many methods twice:

void f(X...x) {
 f(Arrays.asList(x));
}
void f(List<X> x) {
 ...
}



More information about the core-libs-dev mailing list