list literal gotcha and suggestion
Joshua Bloch
jjb at google.com
Mon Sep 28 21:43:53 PDT 2009
Paul,
On Mon, Sep 28, 2009 at 7:54 PM, Paul Benedict <pbenedict at apache.org> wrote:
> Josh,
>
> I thought the proposal used brackets or braces depending on what was the
> left-hand side of the assignment.
Yep.
> If I have my facts straight, I would like
> to see a proposal where that's not the case and only one is actually used.
>
> List<String> stringList = { "1", "2", "3" };
> Set<String> stringSet = { "1", "2", "3" };
> Map<String, String> stringMap = { "1" : "A", "2" : "B", "3" : "C" };
>
This sort of "target typing" is notoriously tricking from a type-theoretic
perspective, and there's very, very little of it in Java. I would be
reluctant to introduce more of it.
>
> I don't think it matters if { } or [ ] is used, but not both.
>
As above, I don't know whether it would be practical to have once syntax do
double duty. I haven't even tried to specify it.
Josh
More information about the coin-dev
mailing list