該方法以 Number 為參數,並根據調用的方法返回一個原始類型。以下是可用方法列表 -
byte byteValue()
short shortValue()
int intValue()
long longValue()
float floatValue()
double doubleValue()
參數− 不需要參數。
Return Value− 返回值是根據調用的值函數返回的原始類型。
示例
以下是方法值的使用示例。
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
相關用法
- Groovy matches()用法及代碼示例
- Groovy after()用法及代碼示例
- Groovy padRight()用法及代碼示例
- Groovy contains()用法及代碼示例
- Groovy exp()用法及代碼示例
- Groovy equals()用法及代碼示例
- Groovy before()用法及代碼示例
- Groovy pow()用法及代碼示例
- Groovy sin()用法及代碼示例
- Groovy concat()用法及代碼示例
- Groovy random()用法及代碼示例
- Groovy endsWith()用法及代碼示例
- Groovy Maps get()用法及代碼示例
- Groovy rint()用法及代碼示例
注:本文由純淨天空篩選整理自 Groovy - xxxValue()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。