src/share/classes/java/util/concurrent/ConcurrentMap.java

Print this page
rev 6858 : 8004518: Add in-place operations to Map
8010122: Add defaults for ConcurrentMap operations to Map
Reviewed-by: darcy, briangoetz, mduigou, dholmes, ulfzibis
Contributed-by: Doug Lea <dl at cs.oswego.edu>, Henry Jen <henry.jen@oracle.com>, Akhil Arora <akhil.arora@oracle.com>, Peter Levart <peter.levart@gmail.com>

*** 55,64 **** --- 55,79 ---- * @author Doug Lea * @param <K> the type of keys maintained by this map * @param <V> the type of mapped values */ public interface ConcurrentMap<K, V> extends Map<K, V> { + + /** + * {@inheritDoc} + * + * @implNote This implementation assumes that the ConcurrentMap cannot + * contain null values and get() returning null unambiguously means no + * mapping is present. Implementations which support null values must + * override this default implementation. + */ + @Override + default V getOrDefault(Object key, V defaultValue) { + V v; + return (null != (v = get(key))) ? v : defaultValue; + } + /** * If the specified key is not already associated * with a value, associate it with the given value. * This is equivalent to * <pre> {@code