Standard library / reflect
reflect.Value.CanConvert()
Check whether this particular value can be converted to the target type without panic. This includes length-dependent slice-to-array conversions. Expected stdout: 'false\n'.
Formal Syntax & Structure
go syntaxgo
func (v Value) CanConvert(t Type) boolParameters & Attributes
| Name | Type | Description |
|---|---|---|
| t | Type | Target or element type, as specified by the operation. |
Return Value
bool
Check whether this particular value can be converted to the target type without panic.
Working Example
Example Snippetgo
package main
import ( "fmt" "reflect")
func main() { v := reflect.ValueOf([]int{1}); fmt.Println(v.CanConvert(reflect.TypeOf([2]int{}))) }