list literal gotcha and suggestion

Bruce Chapman brucechapman at paradise.net.nz
Thu Oct 8 02:31:43 PDT 2009


Hi all,

I have been half following this discussion, a sick family member is 
preventing much more.

Here's a WILD IDEA that might (or more likely not ) spark someone toward 
a solution.  I don't feel qualified to unilateral decide this won't fly.

Given map syntax is { k1 : v1 , k2 : v2 }

then ':' is used as the separator between the ordered elements, and ',' 
the separator between the unordered unique elements.

Therefore following the same pattern

set syntax is { A , B , C } an unordered collection of unique elements 
(just a Map.keySet() is a Set

and list syntax is { A : B : A : C } an ordered collection allowing 
duplicates

which leaves three ambiguities

{} may be an empty set, empty list or empty map   (1)

{A} may be a Set or List of one element (2)

{A : B} may be a map with one Map.Entry, or a list of 2 elements (3)

So API gurus?...

from (1) above - is it possible to create a class that complies 
simultaneously with Map, List and Set provided it is empty?

from (2) above - is it possible to create a class  that complies 
simultaneously with Set and List provided there is exactly one element?

from (3) above is it possible to create a class the complies 
simultaneously with Map and List provided the Map has only a single 
entry, and the List has exactly two values?

if we can satisfy these requirements then the syntax could be made to 
work, with the compiled code generating one of several objects - all 
immutable

LiteralSet implements Set<T>  (where T is lowest common supertype of all 
elements)
LiteralMap implements Map<K,V>  (where K and V are lowest common 
supertypes of all keys and values respectively)
LiteralList implements List<T> (where T is lowest common supertype of 
all elements)

EmptyLiteralCollection implements List<?>,Map<?,?>,Set<?>
LiteralSingleCollection implements List<T>, Set<T> (where T is type of 
the element)
LiteralSingleMapOrTwoList implements List<T>,Map<K,V>  (where T is 
lowest common supertype of K and V)

Someone please tell me why one of (1), (2) or (3) is not possible.

Bruce

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