当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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–



相关用法


注:本文由纯净天空筛选整理自gopaldave大神的英文原创作品 AtomicLong intValue() method in Java with examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。