# AtomicReference

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Ctors](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicReference#pubctors)\|[Methods](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicReference#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicReference#inhmethods)  

# AtomicReference

`
public


class
AtomicReference
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


implements

`[Serializable](https://developer.android.com/reference/java/io/Serializable)`


`

|---|--------------------------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | java.util.concurrent.atomic.AtomicReference\<V\> |

<br />

*** ** * ** ***

An object reference that may be updated atomically. See the[VarHandle](https://developer.android.com/reference/java/lang/invoke/VarHandle)specification for descriptions of the properties of atomic accesses.

## Summary

|                                                                                            ### Public constructors                                                                                             ||
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[AtomicReference](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicReference#AtomicReference())`() ` Creates a new AtomicReference with null initial value.                     |
| ` `[AtomicReference](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicReference#AtomicReference(V))`(V initialValue) ` Creates a new AtomicReference with the given initial value. |

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                  ### Public methods                                                                                                                                                                                                                                                                                                                                                                                                                                                                  ||
|-----------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` final V`                                                            | ` `[accumulateAndGet](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicReference#accumulateAndGet(V,%20java.util.function.BinaryOperator<V>))`(V x, `[BinaryOperator](https://developer.android.com/reference/java/util/function/BinaryOperator)`<V> accumulatorFunction) ` Atomically updates (with memory effects as specified by[VarHandle.compareAndSet(Object)](https://developer.android.com/reference/java/lang/invoke/VarHandle#compareAndSet(java.lang.Object[]))) the current value with the results of applying the given function to the current and given values, returning the updated value.                                                                                                                                                                                                                                          |
| ` final V`                                                            | ` `[compareAndExchange](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicReference#compareAndExchange(V,%20V))`(V expectedValue, V newValue) ` Atomically sets the value to`newValue`if the current value, referred to as the*witness value* ,`== expectedValue`, with memory effects as specified by[VarHandle.compareAndExchange](https://developer.android.com/reference/java/lang/invoke/VarHandle#compareAndExchange(java.lang.Object[])).                                                                                                                                                                                                                                                                                                                                                                                                      |
| ` final V`                                                            | ` `[compareAndExchangeAcquire](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicReference#compareAndExchangeAcquire(V,%20V))`(V expectedValue, V newValue) ` Atomically sets the value to`newValue`if the current value, referred to as the*witness value* ,`== expectedValue`, with memory effects as specified by[VarHandle.compareAndExchangeAcquire](https://developer.android.com/reference/java/lang/invoke/VarHandle#compareAndExchangeAcquire(java.lang.Object[])).                                                                                                                                                                                                                                                                                                                                                                          |
| ` final V`                                                            | ` `[compareAndExchangeRelease](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicReference#compareAndExchangeRelease(V,%20V))`(V expectedValue, V newValue) ` Atomically sets the value to`newValue`if the current value, referred to as the*witness value* ,`== expectedValue`, with memory effects as specified by[VarHandle.compareAndExchangeRelease](https://developer.android.com/reference/java/lang/invoke/VarHandle#compareAndExchangeRelease(java.lang.Object[])).                                                                                                                                                                                                                                                                                                                                                                          |
| ` final boolean`                                                      | ` `[compareAndSet](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicReference#compareAndSet(V,%20V))`(V expectedValue, V newValue) ` Atomically sets the value to`newValue`if the current value`== expectedValue`, with memory effects as specified by[VarHandle.compareAndSet](https://developer.android.com/reference/java/lang/invoke/VarHandle#compareAndSet(java.lang.Object[])).                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| ` final V`                                                            | ` `[get](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicReference#get())`() ` Returns the current value, with memory effects as specified by[VarHandle.getVolatile](https://developer.android.com/reference/java/lang/invoke/VarHandle#getVolatile(java.lang.Object[])).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| ` final V`                                                            | ` `[getAcquire](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicReference#getAcquire())`() ` Returns the current value, with memory effects as specified by[VarHandle.getAcquire](https://developer.android.com/reference/java/lang/invoke/VarHandle#getAcquire(java.lang.Object[])).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| ` final V`                                                            | ` `[getAndAccumulate](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicReference#getAndAccumulate(V,%20java.util.function.BinaryOperator<V>))`(V x, `[BinaryOperator](https://developer.android.com/reference/java/util/function/BinaryOperator)`<V> accumulatorFunction) ` Atomically updates (with memory effects as specified by[VarHandle.compareAndSet(Object)](https://developer.android.com/reference/java/lang/invoke/VarHandle#compareAndSet(java.lang.Object[]))) the current value with the results of applying the given function to the current and given values, returning the previous value.                                                                                                                                                                                                                                         |
| ` final V`                                                            | ` `[getAndSet](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicReference#getAndSet(V))`(V newValue) ` Atomically sets the value to`newValue`and returns the old value, with memory effects as specified by[VarHandle.getAndSet](https://developer.android.com/reference/java/lang/invoke/VarHandle#getAndSet(java.lang.Object[])).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ` final V`                                                            | ` `[getAndUpdate](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicReference#getAndUpdate(java.util.function.UnaryOperator<V>))`(`[UnaryOperator](https://developer.android.com/reference/java/util/function/UnaryOperator)`<V> updateFunction) ` Atomically updates (with memory effects as specified by[VarHandle.compareAndSet(Object)](https://developer.android.com/reference/java/lang/invoke/VarHandle#compareAndSet(java.lang.Object[]))) the current value with the results of applying the given function, returning the previous value.                                                                                                                                                                                                                                                                                                   |
| ` final V`                                                            | ` `[getOpaque](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicReference#getOpaque())`() ` Returns the current value, with memory effects as specified by[VarHandle.getOpaque](https://developer.android.com/reference/java/lang/invoke/VarHandle#getOpaque(java.lang.Object[])).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| ` final V`                                                            | ` `[getPlain](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicReference#getPlain())`() ` Returns the current value, with memory semantics of reading as if the variable was declared non-`volatile`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| ` final void`                                                         | ` `[lazySet](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicReference#lazySet(V))`(V newValue) ` Sets the value to`newValue`, with memory effects as specified by[VarHandle.setRelease](https://developer.android.com/reference/java/lang/invoke/VarHandle#setRelease(java.lang.Object[])).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| ` final void`                                                         | ` `[set](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicReference#set(V))`(V newValue) ` Sets the value to`newValue`, with memory effects as specified by[VarHandle.setVolatile](https://developer.android.com/reference/java/lang/invoke/VarHandle#setVolatile(java.lang.Object[])).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| ` final void`                                                         | ` `[setOpaque](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicReference#setOpaque(V))`(V newValue) ` Sets the value to`newValue`, with memory effects as specified by[VarHandle.setOpaque](https://developer.android.com/reference/java/lang/invoke/VarHandle#setOpaque(java.lang.Object[])).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| ` final void`                                                         | ` `[setPlain](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicReference#setPlain(V))`(V newValue) ` Sets the value to`newValue`, with memory semantics of setting as if the variable was declared non-`volatile`and non-`final`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| ` final void`                                                         | ` `[setRelease](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicReference#setRelease(V))`(V newValue) ` Sets the value to`newValue`, with memory effects as specified by[VarHandle.setRelease](https://developer.android.com/reference/java/lang/invoke/VarHandle#setRelease(java.lang.Object[])).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ` `[String](https://developer.android.com/reference/java/lang/String) | ` `[toString](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicReference#toString())`() ` Returns the String representation of the current value.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| ` final V`                                                            | ` `[updateAndGet](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicReference#updateAndGet(java.util.function.UnaryOperator<V>))`(`[UnaryOperator](https://developer.android.com/reference/java/util/function/UnaryOperator)`<V> updateFunction) ` Atomically updates (with memory effects as specified by[VarHandle.compareAndSet(Object)](https://developer.android.com/reference/java/lang/invoke/VarHandle#compareAndSet(java.lang.Object[]))) the current value with the results of applying the given function, returning the updated value.                                                                                                                                                                                                                                                                                                    |
| ` final boolean`                                                      | ` `[weakCompareAndSet](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicReference#weakCompareAndSet(V,%20V))`(V expectedValue, V newValue) ` *This method was deprecated in API level 33. This method has plain memory effects but the method name implies volatile memory effects (see methods such as[compareAndExchange(V, V)](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicReference#compareAndExchange(V,%20V))and[compareAndSet(V, V)](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicReference#compareAndSet(V,%20V))). To avoid confusion over plain or volatile memory effects it is recommended that the method[weakCompareAndSetPlain(V, V)](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicReference#weakCompareAndSetPlain(V,%20V))be used instead.* |
| ` final boolean`                                                      | ` `[weakCompareAndSetAcquire](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicReference#weakCompareAndSetAcquire(V,%20V))`(V expectedValue, V newValue) ` Possibly atomically sets the value to`newValue`if the current value`== expectedValue`, with memory effects as specified by[VarHandle.weakCompareAndSetAcquire](https://developer.android.com/reference/java/lang/invoke/VarHandle#weakCompareAndSetAcquire(java.lang.Object[])).                                                                                                                                                                                                                                                                                                                                                                                                          |
| ` final boolean`                                                      | ` `[weakCompareAndSetPlain](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicReference#weakCompareAndSetPlain(V,%20V))`(V expectedValue, V newValue) ` Possibly atomically sets the value to`newValue`if the current value`== expectedValue`, with memory effects as specified by[VarHandle.weakCompareAndSetPlain](https://developer.android.com/reference/java/lang/invoke/VarHandle#weakCompareAndSetPlain(java.lang.Object[])).                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ` final boolean`                                                      | ` `[weakCompareAndSetRelease](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicReference#weakCompareAndSetRelease(V,%20V))`(V expectedValue, V newValue) ` Possibly atomically sets the value to`newValue`if the current value`== expectedValue`, with memory effects as specified by[VarHandle.weakCompareAndSetRelease](https://developer.android.com/reference/java/lang/invoke/VarHandle#weakCompareAndSetRelease(java.lang.Object[])).                                                                                                                                                                                                                                                                                                                                                                                                          |
| ` final boolean`                                                      | ` `[weakCompareAndSetVolatile](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicReference#weakCompareAndSetVolatile(V,%20V))`(V expectedValue, V newValue) ` Possibly atomically sets the value to`newValue`if the current value`== expectedValue`, with memory effects as specified by[VarHandle.weakCompareAndSet](https://developer.android.com/reference/java/lang/invoke/VarHandle#weakCompareAndSet(java.lang.Object[])).                                                                                                                                                                                                                                                                                                                                                                                                                      |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||

## Public constructors

### AtomicReference

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public AtomicReference ()
```

Creates a new AtomicReference with null initial value.

<br />

### AtomicReference

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public AtomicReference (V initialValue)
```

Creates a new AtomicReference with the given initial value.

<br />

|                  Parameters                   ||
|----------------|-------------------------------|
| `initialValue` | `V`: the initial value <br /> |

## Public methods

### accumulateAndGet

Added in[API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final V accumulateAndGet (V x, 
                BinaryOperator<V> accumulatorFunction)
```

Atomically updates (with memory effects as specified by[VarHandle.compareAndSet(Object)](https://developer.android.com/reference/java/lang/invoke/VarHandle#compareAndSet(java.lang.Object[]))) the current value with the results of applying the given function to the current and given values, returning the updated value. The function should be side-effect-free, since it may be re-applied when attempted updates fail due to contention among threads. The function is applied with the current value as its first argument, and the given update as the second argument.

<br />

|                                          Parameters                                          ||
|-----------------------|-----------------------------------------------------------------------|
| `x`                   | `V`: the update value <br />                                          |
| `accumulatorFunction` | `BinaryOperator`: a side-effect-free function of two arguments <br /> |

|            Returns            ||
|-----|--------------------------|
| `V` | the updated value <br /> |

### compareAndExchange

Added in[API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final V compareAndExchange (V expectedValue, 
                V newValue)
```

Atomically sets the value to`newValue`if the current value, referred to as the*witness value* ,`== expectedValue`, with memory effects as specified by[VarHandle.compareAndExchange](https://developer.android.com/reference/java/lang/invoke/VarHandle#compareAndExchange(java.lang.Object[])).

<br />

|                   Parameters                    ||
|-----------------|--------------------------------|
| `expectedValue` | `V`: the expected value <br /> |
| `newValue`      | `V`: the new value <br />      |

|                                           Returns                                           ||
|-----|----------------------------------------------------------------------------------------|
| `V` | the*witness value* , which will be the same as the expected value if successful <br /> |

### compareAndExchangeAcquire

Added in[API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final V compareAndExchangeAcquire (V expectedValue, 
                V newValue)
```

Atomically sets the value to`newValue`if the current value, referred to as the*witness value* ,`== expectedValue`, with memory effects as specified by[VarHandle.compareAndExchangeAcquire](https://developer.android.com/reference/java/lang/invoke/VarHandle#compareAndExchangeAcquire(java.lang.Object[])).

<br />

|                   Parameters                    ||
|-----------------|--------------------------------|
| `expectedValue` | `V`: the expected value <br /> |
| `newValue`      | `V`: the new value <br />      |

|                                           Returns                                           ||
|-----|----------------------------------------------------------------------------------------|
| `V` | the*witness value* , which will be the same as the expected value if successful <br /> |

### compareAndExchangeRelease

Added in[API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final V compareAndExchangeRelease (V expectedValue, 
                V newValue)
```

Atomically sets the value to`newValue`if the current value, referred to as the*witness value* ,`== expectedValue`, with memory effects as specified by[VarHandle.compareAndExchangeRelease](https://developer.android.com/reference/java/lang/invoke/VarHandle#compareAndExchangeRelease(java.lang.Object[])).

<br />

|                   Parameters                    ||
|-----------------|--------------------------------|
| `expectedValue` | `V`: the expected value <br /> |
| `newValue`      | `V`: the new value <br />      |

|                                           Returns                                           ||
|-----|----------------------------------------------------------------------------------------|
| `V` | the*witness value* , which will be the same as the expected value if successful <br /> |

### compareAndSet

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final boolean compareAndSet (V expectedValue, 
                V newValue)
```

Atomically sets the value to`newValue`if the current value`== expectedValue`, with memory effects as specified by[VarHandle.compareAndSet](https://developer.android.com/reference/java/lang/invoke/VarHandle#compareAndSet(java.lang.Object[])).

<br />

|                   Parameters                    ||
|-----------------|--------------------------------|
| `expectedValue` | `V`: the expected value <br /> |
| `newValue`      | `V`: the new value <br />      |

|                                                         Returns                                                          ||
|-----------|---------------------------------------------------------------------------------------------------------------|
| `boolean` | `true`if successful. False return indicates that the actual value was not equal to the expected value. <br /> |

### get

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final V get ()
```

Returns the current value, with memory effects as specified by[VarHandle.getVolatile](https://developer.android.com/reference/java/lang/invoke/VarHandle#getVolatile(java.lang.Object[])).

<br />

|            Returns            ||
|-----|--------------------------|
| `V` | the current value <br /> |

### getAcquire

Added in[API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final V getAcquire ()
```

Returns the current value, with memory effects as specified by[VarHandle.getAcquire](https://developer.android.com/reference/java/lang/invoke/VarHandle#getAcquire(java.lang.Object[])).

<br />

|        Returns        ||
|-----|------------------|
| `V` | the value <br /> |

### getAndAccumulate

Added in[API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final V getAndAccumulate (V x, 
                BinaryOperator<V> accumulatorFunction)
```

Atomically updates (with memory effects as specified by[VarHandle.compareAndSet(Object)](https://developer.android.com/reference/java/lang/invoke/VarHandle#compareAndSet(java.lang.Object[]))) the current value with the results of applying the given function to the current and given values, returning the previous value. The function should be side-effect-free, since it may be re-applied when attempted updates fail due to contention among threads. The function is applied with the current value as its first argument, and the given update as the second argument.

<br />

|                                          Parameters                                          ||
|-----------------------|-----------------------------------------------------------------------|
| `x`                   | `V`: the update value <br />                                          |
| `accumulatorFunction` | `BinaryOperator`: a side-effect-free function of two arguments <br /> |

|            Returns             ||
|-----|---------------------------|
| `V` | the previous value <br /> |

### getAndSet

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final V getAndSet (V newValue)
```

Atomically sets the value to`newValue`and returns the old value, with memory effects as specified by[VarHandle.getAndSet](https://developer.android.com/reference/java/lang/invoke/VarHandle#getAndSet(java.lang.Object[])).

<br />

|              Parameters               ||
|------------|---------------------------|
| `newValue` | `V`: the new value <br /> |

|            Returns             ||
|-----|---------------------------|
| `V` | the previous value <br /> |

### getAndUpdate

Added in[API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final V getAndUpdate (UnaryOperator<V> updateFunction)
```

Atomically updates (with memory effects as specified by[VarHandle.compareAndSet(Object)](https://developer.android.com/reference/java/lang/invoke/VarHandle#compareAndSet(java.lang.Object[]))) the current value with the results of applying the given function, returning the previous value. The function should be side-effect-free, since it may be re-applied when attempted updates fail due to contention among threads.

<br />

|                              Parameters                               ||
|------------------|-----------------------------------------------------|
| `updateFunction` | `UnaryOperator`: a side-effect-free function <br /> |

|            Returns             ||
|-----|---------------------------|
| `V` | the previous value <br /> |

### getOpaque

Added in[API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final V getOpaque ()
```

Returns the current value, with memory effects as specified by[VarHandle.getOpaque](https://developer.android.com/reference/java/lang/invoke/VarHandle#getOpaque(java.lang.Object[])).

<br />

|        Returns        ||
|-----|------------------|
| `V` | the value <br /> |

### getPlain

Added in[API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final V getPlain ()
```

Returns the current value, with memory semantics of reading as if the variable was declared non-`volatile`.

<br />

|        Returns        ||
|-----|------------------|
| `V` | the value <br /> |

### lazySet

Added in[API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final void lazySet (V newValue)
```

Sets the value to`newValue`, with memory effects as specified by[VarHandle.setRelease](https://developer.android.com/reference/java/lang/invoke/VarHandle#setRelease(java.lang.Object[])).

<br />

|              Parameters               ||
|------------|---------------------------|
| `newValue` | `V`: the new value <br /> |

### set

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final void set (V newValue)
```

Sets the value to`newValue`, with memory effects as specified by[VarHandle.setVolatile](https://developer.android.com/reference/java/lang/invoke/VarHandle#setVolatile(java.lang.Object[])).

<br />

|              Parameters               ||
|------------|---------------------------|
| `newValue` | `V`: the new value <br /> |

### setOpaque

Added in[API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final void setOpaque (V newValue)
```

Sets the value to`newValue`, with memory effects as specified by[VarHandle.setOpaque](https://developer.android.com/reference/java/lang/invoke/VarHandle#setOpaque(java.lang.Object[])).

<br />

|              Parameters               ||
|------------|---------------------------|
| `newValue` | `V`: the new value <br /> |

### setPlain

Added in[API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final void setPlain (V newValue)
```

Sets the value to`newValue`, with memory semantics of setting as if the variable was declared non-`volatile`and non-`final`.

<br />

|              Parameters               ||
|------------|---------------------------|
| `newValue` | `V`: the new value <br /> |

### setRelease

Added in[API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final void setRelease (V newValue)
```

Sets the value to`newValue`, with memory effects as specified by[VarHandle.setRelease](https://developer.android.com/reference/java/lang/invoke/VarHandle#setRelease(java.lang.Object[])).

<br />

|              Parameters               ||
|------------|---------------------------|
| `newValue` | `V`: the new value <br /> |

### toString

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public String toString ()
```

Returns the String representation of the current value.

<br />

|                                                          Returns                                                          ||
|--------------------------------------------------------------------|-------------------------------------------------------|
| [String](https://developer.android.com/reference/java/lang/String) | the String representation of the current value <br /> |

### updateAndGet

Added in[API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final V updateAndGet (UnaryOperator<V> updateFunction)
```

Atomically updates (with memory effects as specified by[VarHandle.compareAndSet(Object)](https://developer.android.com/reference/java/lang/invoke/VarHandle#compareAndSet(java.lang.Object[]))) the current value with the results of applying the given function, returning the updated value. The function should be side-effect-free, since it may be re-applied when attempted updates fail due to contention among threads.

<br />

|                              Parameters                               ||
|------------------|-----------------------------------------------------|
| `updateFunction` | `UnaryOperator`: a side-effect-free function <br /> |

|            Returns            ||
|-----|--------------------------|
| `V` | the updated value <br /> |

### weakCompareAndSet

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Deprecated in[API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final boolean weakCompareAndSet (V expectedValue, 
                V newValue)
```

<br />

**This method was deprecated in API level 33.**   
This method has plain memory effects but the method name implies volatile memory effects (see methods such as[compareAndExchange(V, V)](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicReference#compareAndExchange(V,%20V))and[compareAndSet(V, V)](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicReference#compareAndSet(V,%20V))). To avoid confusion over plain or volatile memory effects it is recommended that the method[weakCompareAndSetPlain(V, V)](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicReference#weakCompareAndSetPlain(V,%20V))be used instead.

Possibly atomically sets the value to`newValue`if the current value`== expectedValue`, with memory effects as specified by[VarHandle.weakCompareAndSetPlain](https://developer.android.com/reference/java/lang/invoke/VarHandle#weakCompareAndSetPlain(java.lang.Object[])).

<br />

|                   Parameters                    ||
|-----------------|--------------------------------|
| `expectedValue` | `V`: the expected value <br /> |
| `newValue`      | `V`: the new value <br />      |

|                Returns                ||
|-----------|----------------------------|
| `boolean` | `true`if successful <br /> |

**See also:**

- [weakCompareAndSetPlain(V, V)](https://developer.android.com/reference/java/util/concurrent/atomic/AtomicReference#weakCompareAndSetPlain(V,%20V))  

### weakCompareAndSetAcquire

Added in[API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final boolean weakCompareAndSetAcquire (V expectedValue, 
                V newValue)
```

Possibly atomically sets the value to`newValue`if the current value`== expectedValue`, with memory effects as specified by[VarHandle.weakCompareAndSetAcquire](https://developer.android.com/reference/java/lang/invoke/VarHandle#weakCompareAndSetAcquire(java.lang.Object[])).

<br />

|                   Parameters                    ||
|-----------------|--------------------------------|
| `expectedValue` | `V`: the expected value <br /> |
| `newValue`      | `V`: the new value <br />      |

|                Returns                ||
|-----------|----------------------------|
| `boolean` | `true`if successful <br /> |

### weakCompareAndSetPlain

Added in[API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final boolean weakCompareAndSetPlain (V expectedValue, 
                V newValue)
```

Possibly atomically sets the value to`newValue`if the current value`== expectedValue`, with memory effects as specified by[VarHandle.weakCompareAndSetPlain](https://developer.android.com/reference/java/lang/invoke/VarHandle#weakCompareAndSetPlain(java.lang.Object[])).

<br />

|                   Parameters                    ||
|-----------------|--------------------------------|
| `expectedValue` | `V`: the expected value <br /> |
| `newValue`      | `V`: the new value <br />      |

|                Returns                ||
|-----------|----------------------------|
| `boolean` | `true`if successful <br /> |

### weakCompareAndSetRelease

Added in[API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final boolean weakCompareAndSetRelease (V expectedValue, 
                V newValue)
```

Possibly atomically sets the value to`newValue`if the current value`== expectedValue`, with memory effects as specified by[VarHandle.weakCompareAndSetRelease](https://developer.android.com/reference/java/lang/invoke/VarHandle#weakCompareAndSetRelease(java.lang.Object[])).

<br />

|                   Parameters                    ||
|-----------------|--------------------------------|
| `expectedValue` | `V`: the expected value <br /> |
| `newValue`      | `V`: the new value <br />      |

|                Returns                ||
|-----------|----------------------------|
| `boolean` | `true`if successful <br /> |

### weakCompareAndSetVolatile

Added in[API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final boolean weakCompareAndSetVolatile (V expectedValue, 
                V newValue)
```

Possibly atomically sets the value to`newValue`if the current value`== expectedValue`, with memory effects as specified by[VarHandle.weakCompareAndSet](https://developer.android.com/reference/java/lang/invoke/VarHandle#weakCompareAndSet(java.lang.Object[])).

<br />

|                   Parameters                    ||
|-----------------|--------------------------------|
| `expectedValue` | `V`: the expected value <br /> |
| `newValue`      | `V`: the new value <br />      |

|                Returns                ||
|-----------|----------------------------|
| `boolean` | `true`if successful <br /> |