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) Value

Parameters & Attributes

NameTypeDescription
tTypeTarget 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()) }
Go Reference