我正在尝试使用反射在Go语言中将指向结构体的指针设置为通过interface{}
传入的nil
。
我有这个示例程序,但它总是打印false,因为a没有设置为nil
。我做错了什么?
package main
import "reflect"
type MyStruct struct {}
func main() {
a := &MyStruct{}
wipePassed(a)
println(a == nil)
}
func wipePassed(r interface{}){
v := reflect.ValueOf(&r)
p := v.Elem()
p.Set(reflect.Zero(p.Type()))
}