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

