list literal gotcha and suggestion
Joshua Bloch
jjb at google.com
Mon Sep 28 22:34:31 PDT 2009
Paul,
On Mon, Sep 28, 2009 at 10:28 PM, Paul Benedict <pbenedict at apache.org>wrote:
> 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.
Usually it won't compile: you can't assign a Set to a List or vice-versa.
Nick's example was carefully chosen: he invoked a constructor that took a
Collection, which admits either a Set or a List.
> 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.
Agreed, I do think the syntax we settled on is reasonably evocative,
memorable, and consistent with other languages. Braces (AKA curly braces)
are used to represent a Set in mathematical notation, and square brackets
are used to index into and to declare arrays, which are list-like.
> 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?
>
I think it's probably the best that we can do, but I could be wrong. I will
investigate other options.
Josh
More information about the coin-dev
mailing list