list literal gotcha and suggestion
Ruslan Shevchenko
rssh at gradsoft.com.ua
Mon Sep 28 17:53:05 PDT 2009
> Le 29/09/2009 06:43, Joshua Bloch a Иcrit :
>> 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.
>>
>
> The question here is, what is the runtime class of foo, if foo is
> defined like that :
> Collection<String> foo = { "1", "2", "3" };
>
Why this situation differ from
List<String> l = { "1","2","3","4" };
(l will be ArrayList or LinkedList ?)
if we know, that for 'List' exists default implementation class, then we
can or bind default implementation class to collection, or just say that
Collection have no default implementation class.
>>
>>
>>> 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
>>
>>
>
> RИmi
>
>
More information about the coin-dev
mailing list