[concurrency-interest] Immutable Entry objects in j.u.TreeMap

Ashwin Jayaprakash ashwin.jayaprakash at gmail.com
Mon Apr 5 18:47:18 EDT 2010


I was looking at the JDK 6 java.util.TreeMap source code to see if any of
the xxEntry methods were returning actual Entry objects or immutable
snapshots like in j.u.c.ConcurrentSkipMap. I see that the return values in
TreeMap are confusing. I hope someone here can throw some light on this:

java.util.TreeMap:

1) entrySet, headMap, tailMap - seem to return Map.Entry references that are
still referred to by the map. There's no confusion here.

2) firstEntry, lastEntry, lowerEntry, floorEntry...ceilingEntry - these wrap
the actual Map.Entry objects with exportEntry(). So, these are actually
returning AbstractMap.SimpleImmutableEntry instances. Why the difference?
Why isn't setValue(xx) not allowed on these entries?

Ashwin.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20100405/1487e2b8/attachment.html>


More information about the Concurrency-interest mailing list