package main
import "fmt"
func doStuff(q interface{}) {
*q = MyStruct{2}
}
type MyStruct struct {
f1 int
}
func main() {
ms := MyStruct{1}
doStuff(&ms)
fmt.Printf("Hello, playground: %v\n", ms)
}
Is it possible to set ms through pointer q to have new value MyStruct{2}? I am getting this error invalid indirect of q (type interface {})
interface{}is not a pointer type, so you cannot use pointer indirection on it.interface{}as "any type". This is wrong.interface{}is not "any type" it is the empty interface, literallyinterface{}and a distinct fixed type like uint16, chan bool, []string or io.Reader. It is worth redoing the Tour of Go once more to become familiar with Go's types system.