What is the difference between these two structs other than that they aren't considered equivalent?
package main
func main() {}
func f1(s struct{a int;b int}) { f2(s) }
func f2(s struct{b int;a int}) {}
$ go run a.go
# command-line-arguments
./a.go:3: cannot use s (type struct { a int; b int }) as type struct { b int; a int } in argument to f2
Note: this does compile:
package main
func main() {}
func f1(s struct{a int;b int}) { f2(s) }
func f2(s struct{a int;b int}) {}
"The order of structs' fields is important on the low level" How?
This will impact the reflection, like func (v Value) Field(i int) Value
:
Field returns the i'th field of the struct v
The first field 'a' in the first structure wouldn't be the same first in the second structure.
That also will influence serialization with marshaler methods (encoding package).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With