list literal gotcha and suggestion
Paul Benedict
pbenedict at apache.org
Wed Oct 7 16:50:53 PDT 2009
Reinier,
> Q: Should the syntax of initializing remain uniform in Java?
> A: Obviously not; I dont think anybody is considering "new Foo[] { foo1,
> foo2, foo3};" to be a decent syntax for a _list_ literal. I'm guessing
> that's not what you meant, though. Rephrase the question?
When I say "uniform initialization syntax", I mean curly braces would
continue to indicate a series of literal values.
int[] a = {1, 2, 3};
List<Integer> b = {1, 2, 3};
Set<Integer> c = {1, 2, 3};
Map<Integer, String> d = {{1, "apple"}, {2, "orange"}, {3, "banana"}};
As I opined before, I think one syntax is easy and naturally builds
upon what is already laid down for array initialization. It to me is
consistent with Java's syntactical "feel" -- while others have readily
admitted PHP/Perl influence for the current proposal.
> Q: Can operations be performed on the collection literal? 3.toString() is
> illegal -- why would { 1, 2 }.toSet() ?
> A: Unless you propose that "FooBar".toLowerCase(); is to be made illegal, I
> don't really get your point here.
I think "FooBar" is a poor example because String-literals can only be
typed as Strings. If you can entertain that collection literals do not
to have a type except by compiler conversion rules (as would be with a
uniform initialization syntax), then refer to Neal's prior explanation
on this matter. I think his explanation was adequate.
Paul
Paul
More information about the coin-dev
mailing list