AtomicReference類的getPlain()方法用於返回AtomicReference對象的當前值,並具有讀取內存的語義,就像將該變量聲明為非易失性一樣。
用法:
public final V getPlain()
參數:此方法不接受任何內容。
返回值:此方法返回AtomicReference的值。
以下示例程序旨在說明getPlain()方法:
程序1:
// Java program to demonstrate
// AtomicReference.getPlain() method
import java.util.concurrent.atomic.AtomicReference;
public class GFG {
public static void main(String[] args)
{
// create an atomic reference object.
AtomicReference<Integer> ref
= new AtomicReference<Integer>();
// set some value
ref.set(564324);
// get value using getPlain()
int value = ref.getPlain();
// print
System.out.println("Value = " + value);
}
}
輸出:
程序2:
// Java program to demonstrate
// AtomicReference.getPlain() method
import java.util.concurrent.atomic.AtomicReference;
public class GFG {
public static void main(String[] args)
{
// create an atomic reference object.
AtomicReference<String> ref
= new AtomicReference<String>();
// set some value
ref.set("AtomicReference value");
// get value getPlain()
String value = ref.getPlain();
// print
System.out.println("Value = " + value);
}
}
輸出:
相關用法
- Java AtomicReferenceArray getPlain()用法及代碼示例
- Java AtomicReference set()用法及代碼示例
- Java AtomicReference get()用法及代碼示例
- Java AtomicReference compareAndSet()用法及代碼示例
- Java AtomicReference lazySet()用法及代碼示例
- Java AtomicReference getAndAccumulate()用法及代碼示例
- Java AtomicReference setRelease()用法及代碼示例
- Java AtomicReference getAndUpdate()用法及代碼示例
- Java AtomicReference setOpaque()用法及代碼示例
- Java AtomicReference accumulateAndGet()用法及代碼示例
- Java AtomicReference getAcquire()用法及代碼示例
- Java AtomicReference getOpaque()用法及代碼示例
- Java AtomicReference setPlain()用法及代碼示例
- Java AtomicReference getAndSet()用法及代碼示例
- Java AtomicReference toString()用法及代碼示例
注:本文由純淨天空篩選整理自AmanSingh2210大神的英文原創作品 AtomicReference getPlain() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。