Asking about the interesting behaviours of TreeMap.putAll

Doug Lea dl at cs.oswego.edu
Mon Mar 5 11:10:27 UTC 2012


On 03/05/12 05:53, David Holmes wrote:
> Charles,
>
> I just realized that your webrev is for Map not AbstractMap and that it is Map
> the states putAll does a put() on each entry.

No, Map says:

The effect of this call is equivalent to that of calling put(k, v) on this map 
once for each mapping from key k to value v in the specified map.


It does NOT say that put is called. There are many similar cases
in Collections, where specs of some methods are stated in terms of
behavioral equivalence to others, with no implication that those
others are actually called. For now-questionable reasons,
Abstract* classes go further than this and state that they actually
perform various calls.

Concrete classes should and do override inhereited javadoc to kill
these Abstract* descriptions whenever they are overridden
(which sadly often means pasting them in and the deleting
some sentences). TreeMap.putAll does so. So I think that
this is Not A Bug.

-Doug






More information about the core-libs-dev mailing list