Groovy - xxxValue ()

Questo metodo assume il numero come parametro e restituisce un tipo primitivo basato sul metodo invocato. Di seguito è riportato l'elenco dei metodi disponibili:

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

Parameters - Nessun parametro richiesto.

Return Value - Il valore restituito è il tipo primitivo restituito a seconda della funzione valore che viene chiamata.

Esempio

Di seguito è riportato un esempio di utilizzo dei valori del metodo.

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

Quando eseguiamo il programma sopra, otterremo il seguente risultato:

5.0 
5 
5.0 
5 
5 
5