第一种情况:
sl:=[]int{1,2,3}
psl:=reflect.SliceHeader(sl)
fmt.Println(psl)
报错:cannot convert expression of type []int to type SliceHeader
第二种情况:
var psl []int
sl:=[]int{1,2,3}
psl=reflect.SliceHeader(sl)
fmt.Println(psl)
报错: cannot convert expression of type []int to type SliceHeader; cannot use reflect.SliceHeader(sl) (type SliceHeader) as type []int in assignment
初学go,为什么sliceheader类型和slice类型不能互转?
有疑问加站长微信联系(非本文作者)

根据 go 的语法,一个 具名类型和 slice,这样强转肯定不行啊,编译器不允许
嗯,谢谢回答。sliceheader是个有三个成员变量的结构体,那slice内部是什么样子的?你说的这个具名类型存在的意义是啥?就只是为了这个
sh := (*reflect.SliceHeader)(unsafe.Pointer(&s))
?slice 是编译器实现的,虽然内部结构和 sliceheader 类似。文档有说明,SliceHeader 在反射包中,是 slice 运行时的表示。
不能修改的吗,回复错帖子了。。。
嗯,没有提供修改的功能
修改?修改啥?
原来如此,好的,谢谢!