Standard library / reflect
reflect.Value.Convert()
Convert using Go conversion rules, which may lose precision or panic if the value cannot be converted. Expected stdout: 'int64\n'.
Formal Syntax & Structure
go syntaxgo
func (v Value) Convert(t Type) ValueParameters & Attributes
| Name | Type | Description |
|---|---|---|
| t | Type | Target or element type, as specified by the operation. |
Return Value
Value
Convert using Go conversion rules, which may lose precision or panic if the value cannot be converted.
Working Example
Example Snippetgo
package main
import ( "fmt" "reflect")
func main() { v := reflect.ValueOf(int16(7)); fmt.Println(v.Convert(reflect.TypeOf(int64(0))).Type()) }