list literal gotcha and suggestion

Rémi Forax forax at univ-mlv.fr
Tue Sep 29 00:03:13 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" };

>
>    
>> 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