Groovy xxxValue()方法

2018-12-29 16:18 更新

此方法接受Number作為參數(shù),并基于調(diào)用的方法返回基本類型。 以下是可用的方法列表 -

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

參數(shù) - 無需參數(shù)。

返回值 - 返回值是根據(jù)調(diào)用的值函數(shù)返回的原始類型。

例子

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

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());  
   } 
}

當我們運行上面的程序,我們將得到以下結(jié)果 -

5.0 
5 
5.0 
5 
5 
5 
以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號