Java AtomicLong intValue()方法及示例
Java.util.concurrent.atomic.AtomicLong.intValue() 是java中的一个内置方法,通过做缩小的原始转换,返回当前存储在数据类型为 long 的对象中的值。
语法
public long intValue()
参数: 该函数不接受单一参数。
返回值: 该函数返回当前值。
以下程序说明了上述方法。
程序1 :
// 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
程序2。
// 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://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/AtomicLong.html#intValue-
极客教程