Java中的 AtomicBoolean get() 方法及示例
Java.util.concurrent.atomic.AtomicBoolean.get()是Java中的一个内置方法,它返回日期类型布尔值的当前值。
句法:
public final boolean get()
参数:该函数不接受任何参数。
返回值:函数返回当前值
下面的程序说明了上述函数:
方案一:
// Java Program to demonstrates
// the get() function
import java.util.concurrent.atomic.AtomicBoolean;
public class GFG {
public static void main(String args[])
{
// Initially value as false
AtomicBoolean val
= new AtomicBoolean(false);
// Gets the current value
boolean res = val.get();
System.out.println("current value: "
+ res);
}
}
输出:
current value: false
方案二:
// Java Program to demonstrates
// the get() function
import java.util.concurrent.atomic.AtomicBoolean;
public class GFG {
public static void main(String args[])
{
// Initially value as true
AtomicBoolean val = new AtomicBoolean(true);
// Gets the current value
boolean res = val.get();
System.out.println("current value: "
+ res);
}
}
输出:
current value: true
参考: https: Java/util/concurrent/atomic/AtomicBoolean.html#get–