For further consideration, round 2
Joseph D. Darcy
Joe.Darcy at Sun.COM
Mon Jul 20 13:54:03 PDT 2009
Greg Brown wrote:
>> 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)
>
No, that approach is not feasible for Project Coin; Bob Lee's
"Simplified Varargs Method Invocation"
(http://mail.openjdk.java.net/pipermail/coin-dev/2009-March/000217.html)
is intended to address exactly this problem.
-Joe
More information about the coin-dev
mailing list