list literal gotcha and suggestion

Rémi Forax forax at univ-mlv.fr
Wed Sep 30 05:54:59 PDT 2009


Le 30/09/2009 14:47, Schulz, Stefan a écrit :
> Stephen wrote:
>    
>> List<String>  list = {"1", "2", "3"} - List literal
>> Map<Integer, String>  list = {1 : "1", 2 : "2", 3 : "3"} - Map literal
>> No set literal
>> (I don't think this conflicts with the array literals...)
>>      
> Just wanted to add a little side-note that, despite not being technically confusable with Lists, Map literals would behave exactly like Sets wrt. duplicate keys. I'd rather prefer clearly typed factory methods over potentially confusing literals in the language. The only really awkward thing regarding creation to me are Maps.
>    

Hi Stefan,
I don't follow you. With a literal syntax, the compiler can detect 
duplicate keys at compile time
if keys are constants.

> Cheers, Stefan
>    

Rémi




More information about the coin-dev mailing list