list literal gotcha and suggestion

Paul Benedict pbenedict at apache.org
Mon Sep 28 22:28:42 PDT 2009


Josh,

I think using braces or brackets to indicate the correct type is hardly
intuitive or easy to remember. Choosing the wrong syntax by accident will
instantiate the wrong type, and the difference between the brace or bracket
is pretty subtle visually. If Java developers have to begin saying, "Which
syntax do I need to use for a List vs. Set?", then I question the whole
cost-to-benefit-ratio of this "small" (i.e, coin) proposal. I can see the
JDK 7 certification tests already asking this question -- it's a good gotcha
question. Not being a language expert, and recognizing that other languages
already use what's being proposed, the syntax still doesn't pass my common
sense meter. Do the technical justifications really outweigh simplicity?

Paul

On Mon, Sep 28, 2009 at 11:43 PM, Joshua Bloch wrote:

> Paul,
>
> On Mon, Sep 28, 2009 at 7:54 PM, Paul Benedict 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