Language

VarHandle.CompareAndSet(Object[]) Method

Definition

Atomically sets the value of a variable to the newValue with the memory semantics of setVolatile(java.lang.Object...) if the variable's current value, referred to as the witness value, == the expectedValue, as accessed with the memory semantics of getVolatile(java.lang.Object...).

[Android.Runtime.Register("compareAndSet", "([Ljava/lang/Object;)Z", "", ApiSince=33)]
public bool CompareAndSet(params Java.Lang.Object[]? args);
[<Android.Runtime.Register("compareAndSet", "([Ljava/lang/Object;)Z", "", ApiSince=33)>]
member this.CompareAndSet : Java.Lang.Object[] -> bool

Parameters

args
Object[]

the signature-polymorphic parameter list of the form (CT1 ct1,..., CTn ctn, T expectedValue, T newValue), statically represented using varargs.

Returns

true if successful, otherwise false if the witness value was not the same as the expectedValue.

Attributes

Remarks

Atomically sets the value of a variable to the newValue with the memory semantics of setVolatile(java.lang.Object...) if the variable's current value, referred to as the witness value, == the expectedValue, as accessed with the memory semantics of getVolatile(java.lang.Object...). The method signature is of the form (CT1 ct1,..., CTn ctn, T expectedValue, T newValue)boolean. The symbolic type descriptor at the call site of compareAndSet must match the access mode type that is the result of calling accessModeType(VarHandle.AccessMode.COMPARE_AND_SET) on this VarHandle.

Java reference for java.lang.invoke.VarHandle.compareAndSet.

Applies to