다음을 통해 공유


ConcurrentHashMap.ComputeIfAbsent(Object, IFunction) Method

Definition

If the specified key is not already associated with a value, attempts to compute its value using the given mapping function and enters it into this map unless null.

[Android.Runtime.Register("computeIfAbsent", "(Ljava/lang/Object;Ljava/util/function/Function;)Ljava/lang/Object;", "GetComputeIfAbsent_Ljava_lang_Object_Ljava_util_function_Function_Handler", ApiSince=24)]
public virtual Java.Lang.Object? ComputeIfAbsent (Java.Lang.Object key, Java.Util.Functions.IFunction mappingFunction);
[<Android.Runtime.Register("computeIfAbsent", "(Ljava/lang/Object;Ljava/util/function/Function;)Ljava/lang/Object;", "GetComputeIfAbsent_Ljava_lang_Object_Ljava_util_function_Function_Handler", ApiSince=24)>]
abstract member ComputeIfAbsent : Java.Lang.Object * Java.Util.Functions.IFunction -> Java.Lang.Object
override this.ComputeIfAbsent : Java.Lang.Object * Java.Util.Functions.IFunction -> Java.Lang.Object

Parameters

key
Object

key with which the specified value is to be associated

mappingFunction
IFunction

the function to compute a value

Returns

the current (existing or computed) value associated with the specified key, or null if the computed value is null

Implements

Attributes

Remarks

If the specified key is not already associated with a value, attempts to compute its value using the given mapping function and enters it into this map unless null. The entire method invocation is performed atomically. The supplied function is invoked exactly once per invocation of this method if the key is absent, else not at all. Some attempted update operations on this map by other threads may be blocked while computation is in progress, so the computation should be short and simple.

The mapping function must not modify this map during computation.

Java documentation for java.util.concurrent.ConcurrentHashMap.computeIfAbsent(K, java.util.function.Function<? super K, ? extends V>).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to