list literal gotcha and suggestion
Reinier Zwitserloot
reinier at zwitserloot.com
Wed Oct 7 15:13:14 PDT 2009
The recent activity on this list consisted of Neal and I swapping one-
liners. That doesn't really make the case for 'growing consensus of
inadequacy'.
You ask interesting questions, none of which have been handled in
this spinoff discussion on using {} syntax for all different forms of
literals, together with pseudo target typing.
My answers:
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?
Q: are new static methods a decent enhancement regardless of this
proposal?
A: Yes. [Note copious use of google collections API. Also, it's
obvious that Collections.unmodifiableList(Arrays.asList(item1, item2,
item3)); is idiotic, and yet commonly used. Clearly something that
needs fixing.]
Q: Are collection literals immutable or mutable?
A: Immutable. Because immutables win.
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. Of course {1, 2}.toSet()
should be legal. The reason "3.toString()" is not legal is because
autoboxing doesn't work that way. {1, 2} is a list. It's not a vague
unspecified type I'll christen a "NealCollection" which has no methods
until it converts to something. Neal's point that "3" is a special
integer that is assign-type compatible to a byte has no relation
whatsoever to the fact that "3.toString()" doesn't work. That's an
autoboxing issue. Autoboxing was a complicated but neccessary evil.
Let's not introduce them to list literals where they aren't neccessary.
--Reinier Zwitserloot
On 2009/07/10, at 22:55, Paul Benedict wrote:
> Reinier,
>
> I am glad serious opposition doesn't have a time limit. The recent
> activity on the list indicates, at least to me, that there is growing
> consensus that the current proposal is inadequate. Those raising
> issues (definitely more than two) have made very good arguments on the
> limitations and pit-falls of the current syntax. Regardless,
> intentions are good. The discussion is driving towards enhancing and
> correcting -- not torpedoing -- the proposal.
>
> As things stand, these are the issues:
> * Should the syntax of initializing remain uniform in Java?
> * Are new static methods a decent enhancement regardless of this
> proposal?
> * Are collection literals immutable or mutable?
> * Can operations be performed on the collection literal? 3.toString()
> is illegal -- why would { 1, 2 }.toSet() ?
>
> Paul
>
More information about the coin-dev
mailing list