Исходники и презентации
This commit is contained in:
20
lessons/generics_and_reflection/reflect_convertible/main.go
Normal file
20
lessons/generics_and_reflection/reflect_convertible/main.go
Normal file
@ -0,0 +1,20 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func main() {
|
||||
vData := reflect.ValueOf([]int{1, 2, 3})
|
||||
|
||||
tData := vData.Type()
|
||||
t1 := reflect.TypeOf(&[3]int{})
|
||||
t2 := reflect.TypeOf([3]int{})
|
||||
|
||||
fmt.Println(tData.ConvertibleTo(t1))
|
||||
fmt.Println(tData.ConvertibleTo(t2))
|
||||
|
||||
fmt.Println(vData.CanConvert(t1))
|
||||
fmt.Println(vData.CanConvert(t2))
|
||||
}
|
||||
Reference in New Issue
Block a user