| 1234567891011121314151617181920212223242526272829303132 |
- // reflect1.go
- // blog: Laws of Reflection
- package main
- import (
- "fmt"
- "reflect"
- )
- func main() {
- var x float64 = 3.4
- fmt.Println("type:", reflect.TypeOf(x))
- v := reflect.ValueOf(x)
- fmt.Println("value:", v)
- fmt.Println("type:", v.Type())
- fmt.Println("kind:", v.Kind())
- fmt.Println("value:", v.Float())
- fmt.Println(v.Interface())
- fmt.Printf("value is %5.2e\n", v.Interface())
- y := v.Interface().(float64)
- fmt.Println(y)
- }
- /* output:
- type: float64
- value: <float64 Value>
- type: float64
- kind: float64
- value: 3.4
- 3.4
- value is 3.40e+00
- 3.4
- */
|