Groovy xxxValue()方法
2018-12-29 16:18 更新
此方法接受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
以上内容是否对您有帮助:

免费 AI IDE


更多建议: