Indexing access for Lists and Maps considered harmful?

Ruslan Shevchenko rssh at gradsoft.com.ua
Mon Jun 22 08:28:38 PDT 2009


> Hello.
>
> A recent blog post cited in Alex Miller's handy "Java 7 Links"
> (http://java7.tumblr.com) claims that adding indexing support for Lists
> and Maps would be harmful because of an arguably surprising behavior on
> compound assignment.  After
>
> map["a"] = map["b"] = "c";
>
> the new value for key "a" would be the old mapping of "b" and not
> necessarily "c" because a call to the put method returns the old value.
>
> I'm not too concerned about this interaction because compound assignment
> is relatively infrequent; however, I think a lint warning from the
> compiler would be appropriate in this case.  Also, an IDE could color
> the non-array uses of "[]" differently to highlight any potential
> differences in semantics.
>

 Hmm, are semantics of "[]" must be exactly equal to semantics of put ?
 (if I remember, [] proposal come to us without JLS part)
 i. e. it is possible introduce another pair of methods instead put/get,
or just ignore return value of put, i. e. map["b"]="c" will be translated
to pseudocode {map.put("b","c"), c}



> As a meta-comment, I find it odd that if someone wanted to inform the
> coin discussion he or she would not directly email the coin list in
> addition to or instead of posting a blog entry.
>
> -Joe
>
>





More information about the coin-dev mailing list