Groovy - xxxValue()



該方法以數字作為引數,並根據呼叫方法返回一個基本型別。下面列出了可用的方法列表 -

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

引數 - 不需要引數。

返回值 - 返回值是根據呼叫的 value 函式返回的基本型別。

示例

以下是 values 方法的用法示例。

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_numbers.htm
廣告
© . All rights reserved.