Indexing access for Lists and Maps considered harmful?
abies at adres.pl
abies at adres.pl
Tue Jun 23 02:21:11 PDT 2009
Hello,
If we have following statement
String x = coll[0] = "ABC";
it should work in the same way if coll is
a) native String[] array
b) java.util.List<String>
c) java.util.Map<Integer,String>
I think that it would be very suprising to have different behaviour depending on the type of collection.
This means it is not possible to get old value from the map on replace, while using [] operator - but same way as foreach on arrays is missing index, I think it is good tradeoff for having common usage consistent with rest of the language. In the few cases you need return value, you can use normal method call.
With best regards,
Artur Biesiadowski
More information about the coin-dev
mailing list