GO語言"go/constant"包中"Val"函數的用法及代碼示例。
用法:
func Val(x Value) any
Val 返回給定常量的基礎值。由於它返回一個接口,因此由調用者將結果類型斷言為預期類型。可能的動態返回類型是:
x Kind type of result ----------------------------------------- Bool bool String string Int int64 or *big.Int Float *big.Float or *big.Rat everything else nil
例子:
package main
import (
"fmt"
"go/constant"
"math"
)
func main() {
maxint := constant.MakeInt64(math.MaxInt64)
fmt.Printf("%v\n", constant.Val(maxint))
e := constant.MakeFloat64(math.E)
fmt.Printf("%v\n", constant.Val(e))
b := constant.MakeBool(true)
fmt.Printf("%v\n", constant.Val(b))
b = constant.Make(false)
fmt.Printf("%v\n", constant.Val(b))
}
輸出:
9223372036854775807 6121026514868073/2251799813685248 true false
相關用法
- GO Value用法及代碼示例
- GO Values.Get用法及代碼示例
- GO ValidString用法及代碼示例
- GO Values用法及代碼示例
- GO Values.Set用法及代碼示例
- GO Valid用法及代碼示例
- GO ValidRune用法及代碼示例
- GO Values.Has用法及代碼示例
- GO Values.Del用法及代碼示例
- GO Values.Add用法及代碼示例
- GO Value.FieldByIndex用法及代碼示例
- GO Values.Encode用法及代碼示例
- GO Varint用法及代碼示例
- GO PutUvarint用法及代碼示例
- GO Scanner.Scan用法及代碼示例
- GO LeadingZeros32用法及代碼示例
- GO NewFromFiles用法及代碼示例
- GO Regexp.FindString用法及代碼示例
- GO Time.Sub用法及代碼示例
- GO Regexp.FindAllIndex用法及代碼示例
注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 Val。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。