Why doesn't new Map methods generate entry accesses on LinkedHashMap? [Copy]
Doug Lea
dl at cs.oswego.edu
Mon Dec 9 02:51:01 PST 2013
On 12/09/2013 05:11 AM, Paul Sandoz wrote:
> Hi Roman,
>
> On Dec 8, 2013, at 10:29 PM, Roman Leventov <leventov at ya.ru> wrote:
>> Especially getDefault(). Doesn't this violate principle of least astonishment? Details and proof: http://stackoverflow.com/questions/20440136/why-doesnt-new-map-methods-generate-entry-accesses-on-linkedhashmap
>>
>
> Thanks. I believe that all the new (default) Map methods but getOrDefault behave correctly. So i think it is a bug, we need to add something like the following to LinkedHashMap:
>
I agree. Please do this.
-Doug
> public V getOrDefault(Object key, V defaultValue) {
> Node<K,V> e;
> if ((e = getNode(hash(key), key)) == null)
> return defaultValue;
> if (accessOrder)
> afterNodeAccess(e);
> return e.value;
> }
>
> and also update the documentation to clarify (via the implementation specification of the default methods it can be inferred what the behaviour is, but that ain't obvious).
>
> I have logged this bug:
>
> https://bugs.openjdk.java.net/browse/JDK-8029795
>
> Paul.
>
>
>
More information about the jdk8-dev
mailing list