ConcurrentMap.replace

Replaces the entry for a key only if currently mapped to some value. This is equivalent to, for this {@code map}: <pre> {@code if (map.containsKey(key)) return map.put(key, value); else return null;}</pre>

except that the action is performed atomically.

@implNote This implementation intentionally re-abstracts the inappropriate default provided in {@code Map}.

@param key key with which the specified value is associated @param value value to be associated with the specified key @return the previous value associated with the specified key, or {@code null} if there was no mapping for the key. (A {@code null} return can also indicate that the map previously associated {@code null} with the key, if the implementation supports null values.) @throws UnsupportedOperationException if the {@code put} operation is not supported by this map @throws ClassCastException if the class of the specified key or value prevents it from being stored in this map @throws NullPointerException if the specified key or value is null, and this map does not permit null keys or values @throws IllegalArgumentException if some property of the specified key or value prevents it from being stored in this map

  1. bool replace(K key, V oldValue, V newValue)
  2. V replace(K key, V value)
    interface ConcurrentMap(K, V)
    V
    replace
    (
    K key
    ,)

Meta