For further consideration, round 2

Greg Brown gkbrown at mac.com
Mon Jul 20 13:45:11 PDT 2009


> Map would require a bit more effort since there is currently
> no class to represent a key/value pair, but could work something like
> this:
>
> Map<String, Integer> map = HashMap.unmodifiableMap(new
> Map.Pair<String, Integer>("foo", 123),
>         new Map.Pair<String, Integer >("bar", 456));

After doing some quick prototyping, it appears that at least one minor  
language change would help facilitate this approach. The above code  
generates a compiler warning:

"Type safety : A generic array of Map.Pair<String,Integer> is created  
for a varargs parameter"

One way to eliminate this warning would be to make the contents of the  
varargs array immutable (or at least, optionally so). How about  
defining "final" to also extend to the array contents when applied to  
varargs?

public static <K, V> Map<K, V> unmodifiableMap(final Pair<K, V>...  
pairs) {...}

(FYI, I have no idea how feasible this is - just brainstorming)

Greg




More information about the coin-dev mailing list