Java中的 AtomicLong intValue() 方法及示例
Java.util.concurrent.atomic.AtomicLong.intValue()是Java中的一个内置方法,它通过进行缩小原始转换返回当前存储在数据类型为long的对象中的值。
句法:
public long intValue()
参数:该函数不接受单个参数。
返回值:函数返回当前值。
下面的程序说明了上述方法:
方案一:
// Java program that demonstrates
// the intValue() function
import java.util.concurrent.atomic.AtomicLong;
public class GFG {
public static void main(String args[])
{
// Initially value as 0
AtomicLong val = new AtomicLong(0);
long res
= val.intValue();
// Prints the updated value
System.out.println("Current value: "
+ res);
}
}
输出:
Current value: 0
方案二:
// Java program that demonstrates
// the intValue() function
import java.util.concurrent.atomic.AtomicLong;
public class GFG {
public static void main(String args[])
{
// Initially value as 18
AtomicLong val = new AtomicLong(18);
long res = val.intValue();
// Prints the updated value
System.out.println("Current value: "
+ res);
}
}
输出:
Current value: 18
参考: https: Java/util/concurrent/atomic/AtomicLong.html#intValue–