Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

putIfAbsent etc for MutableMaps #692

Open
dlkw opened this issue Sep 27, 2017 · 0 comments
Open

putIfAbsent etc for MutableMaps #692

dlkw opened this issue Sep 27, 2017 · 0 comments

Comments

@dlkw
Copy link
Contributor

dlkw commented Sep 27, 2017

Interface MapMutator<Key, Item> should have a method

shared formal Anything putIfAbsent(Key key, Item item);

which should be refined in MutableMap as

shared formal Item putIfAbsent(Key key, Item item);

There should be also MapMutator methods along the lines of

    shared formal Anything computeIfAbsent(Key key, Item(Object) comp);
    shared formal Anything computeIfPresent(Key key, Item(Object, Object) comp);

which should be refined in MutableMap somehow like (as close as possible to)

    shared formal Item computeIfAbsent(Key key, Item(Key) comp);
    shared formal Item computeIfPresent(Key key, Item(Key, Item) comp);

The latter is unfortunately not possible as written here due to covariance/contravariance clash.

This would not only ease the use of mutable maps in situations where a value must be put into the map when there is no value mapped to the key yet, but also enable the atomical usage of Java concurrent Maps in the same manner as standard Maps.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant