Groovy-xxxvalue

提供:Dev Guides
移動先:案内検索

Groovy-xxxValue()

このメソッドはパラメーターとしてNumberを受け取り、呼び出されたメソッドに基づいてプリミティブ型を返します。 以下は利用可能なメソッドのリストです-

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

パラメータ-パラメータは不要です。

戻り値-戻り値は、呼び出される値関数に応じて返されるプリミティブ型です。

以下は、メソッド値の使用例です。

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