list literal gotcha and suggestion

Mark Thornton mthornton at
Tue Oct 6 03:18:19 PDT 2009

Reinier Zwitserloot wrote:
> These examples all look nice when you assign them to a properly typed  
> variable. The moment you remove that Left-hand-side type context,  
> these kinds of solutions tend to suck (in that it becomes a small  
> nightmare to figure out, from a casual glance, what it is that you're  
> looking at. List? Set? Array? Map?) I suggest that the only practical  
> way to make target typing work is to make these literals illegal  
> unless they are being used as the expression in a variable assignment  
> expression or variable declaration statement. However, one of the main  
> benefits of having literals is that you can inline a list literal with  
> a few elements directly into a method call, which you'd obviously lose  
> if you tack on this requirement. It helps to remember that java's  
> method overloading makes any sort of target typing based on position  
> in method argument list no more than a rough guestimate.
Would it be possible to allow it when the target type is unambiguous?

Mark Thornton

More information about the coin-dev mailing list