Standard library / go/types

go/types.ConvertibleTo()

Reports whether a conversion between two types is permitted. Expected stdout: 'true false\n'.

Formal Syntax & Structure

go syntaxgo
func ConvertibleTo(V, T Type) bool

Parameters & Attributes

NameTypeDescription
VTypeSource or candidate type.
TTypeDestination type or interface, or type to inspect.

Return Value

bool

Reports whether a conversion between two types is permitted.

Working Example

Example Snippetgo
package main
import (  "fmt"  "go/types")
func main() {  fmt.Println(types.ConvertibleTo(types.Typ[types.Int], types.Typ[types.Int64]), types.ConvertibleTo(types.Typ[types.String], types.Typ[types.Bool]))}
Go Reference