當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Groovy xxxValue()用法及代碼示例


該方法以 Number 為參數,並根據調用的方法返回一個原始類型。以下是可用方法列表 -

byte byteValue() 
short shortValue() 
int intValue() 
long longValue() 
float floatValue() 
double doubleValue()

參數− 不需要參數。

Return Value− 返回值是根據調用的值函數返回的原始類型。

示例

以下是方法值的使用示例。

class Example { 
   static void main(String[] args) {  
      Integer x = 5; 
		
      // Converting the number to double primitive type
      println(x.doubleValue()); 
		
      // Converting the number to byte primitive type 
      println(x.byteValue()); 
		
      // Converting the number to float primitive type 
      println(x.floatValue());
		
      // Converting the number to long primitive type 
      println(x.longValue()); 
		
      // Converting the number to short primitive type 
      println(x.shortValue()); 
		
      // Converting the number to int primitive type 
      println(x.intValue());  
   } 
}

當我們運行上述程序時,我們將得到以下結果 -

5.0 
5 
5.0 
5 
5 
5 

相關用法


注:本文由純淨天空篩選整理自 Groovy - xxxValue()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。